cogent icon indicating copy to clipboard operation
cogent copied to clipboard

Error message for Integer type mismatch

Open zilinc opened this issue 9 years ago • 12 comments

Now it says something like:

Mismatch between
   U16
and
   U32
   from constraint U16 :< U32
   when checking that the expression at ("fail_large-code.cogent" (line 244, column 80))
      const_ext2Magic
   has type
      U32

Can be better.

zilinc avatar Nov 28 '16 04:11 zilinc

How can it be improved specifically?

liamoc avatar Nov 28 '16 04:11 liamoc

Suggest using upcast maybe? The constraint U16 :< U32 is actually satisfiable.

zilinc avatar Nov 28 '16 04:11 zilinc

Ah, if you use upcast, right. OK, I can add that.

liamoc avatar Nov 28 '16 04:11 liamoc

Oh btw, we still have functions like u16_to_u32 etc...in ext2 and bilbyfs; should use upcast instead...

zilinc avatar Nov 28 '16 04:11 zilinc

Ummm. let a : U32 = 1 doesn't upcast.

zilinc avatar Nov 28 '16 04:11 zilinc

It shouldn't... it should infer that 1 : U32.

liamoc avatar Nov 28 '16 04:11 liamoc

interestingly if I put 0 to a U32 field in a record, it seems ok

zilinc avatar Nov 28 '16 05:11 zilinc

The type of a numeric literal is inferred from context.. so of course that would work??

liamoc avatar Nov 28 '16 05:11 liamoc

Ah, I might have misunderstood you. Should let a : U32 = 1 typecheck?

zilinc avatar Nov 28 '16 05:11 zilinc

Yes.

liamoc avatar Nov 28 '16 05:11 liamoc

I see. upcast is only for variables (and constants).

zilinc avatar Nov 28 '16 05:11 zilinc

Yes, the literals are no longer given the smallest integer type possible. They are now given whatever integer type is inferred from context (so long as it's big enough to fit the literal).

liamoc avatar Nov 28 '16 05:11 liamoc