c2compiler icon indicating copy to clipboard operation
c2compiler copied to clipboard

Types and values not checked correctly

Open lerno opened this issue 7 years ago • 5 comments

This is possible:

Foo foo = Foo;

Because we do not check during assignment whether Foo an expression-type or an expression with the type Foo.

lerno avatar Dec 01 '18 16:12 lerno

tell me, for the sport, what does it compile to? (as in, if it produces any C code) :smiley:

luciusmagn avatar Dec 01 '18 16:12 luciusmagn

Compiles to test_Foo foo = test_Foo

lerno avatar Dec 01 '18 16:12 lerno

Btw I enabled sizeof(Foo.x) where x is a member of Foo. So I first saw this when it swallowed i32 a = Foo.a for exactly the same reasons. I thought it was my code that had the problem but it was a general bug.

But I actually think it would be good to be able have types as first class constructs. I wrote about it in the forum.

lerno avatar Dec 01 '18 17:12 lerno

You mean base types? (as first class constructs)

Foo.a should just be an error if a is a real member and not a struct function.

On Sat, Dec 1, 2018 at 6:17 PM Christoffer Lerno [email protected] wrote:

Btw I enabled sizeof(Foo.x) where x is a member of Foo. So I first saw this when it swallowed i32 a = Foo.a for exactly the same reasons. I thought it was my code that had the problem but it was a general bug.

But I actually think it would be good to be able have types as first class constructs. I wrote about it in the forum.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/c2lang/c2compiler/issues/80#issuecomment-443441761, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC1mnK5sJHhFkeyq6AooHKfvi3WtHOAks5u0rmsgaJpZM4Y89vD .

bvdberg avatar Dec 02 '18 11:12 bvdberg

No, I mean that the type could be manipulated as an entity and assigned to variables.

”Foo.a” is treated as a reference to the member of Foo called ”a”.

For offset, we can then use offset(Foo.a) instead of offset(Foo, a), it also made sizeof(Foo.a) simple to do.

So the error for i32 a = Foo.a should be ”cannot assign struct member type to i32”

/C

On 2 Dec 2018, at 12:09, Bas van den Berg [email protected] wrote:

You mean base types? (as first class constructs)

Foo.a should just be an error if a is a real member and not a struct function.

On Sat, Dec 1, 2018 at 6:17 PM Christoffer Lerno [email protected] wrote:

Btw I enabled sizeof(Foo.x) where x is a member of Foo. So I first saw this when it swallowed i32 a = Foo.a for exactly the same reasons. I thought it was my code that had the problem but it was a general bug.

But I actually think it would be good to be able have types as first class constructs. I wrote about it in the forum.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/c2lang/c2compiler/issues/80#issuecomment-443441761, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC1mnK5sJHhFkeyq6AooHKfvi3WtHOAks5u0rmsgaJpZM4Y89vD .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/c2lang/c2compiler/issues/80#issuecomment-443499272, or mute the thread https://github.com/notifications/unsubscribe-auth/AABtVXjWam45EndfY9h2ijLwq9EZxdNgks5u07UDgaJpZM4Y89vD.

lerno avatar Dec 02 '18 16:12 lerno