toit icon indicating copy to clipboard operation
toit copied to clipboard

Error message for bad types in number operations should be improved

Open floitsch opened this issue 3 years ago • 1 comments

main:
  x /any := "str"
  print 3 + x

yields

Class 'string' does not have any method 'add_from_small_integer_'.
  0: SmallInteger_.+           <sdk>/core/numbers.toit:966:20
  1: main                      bad.toit:3:11
  2: __entry__.<lambda>        <sdk>/core/entry.toit:48:20

Would be nice to have a type-mismatch error instead.

floitsch avatar Jan 28 '22 11:01 floitsch

Since we are intercepting operations anyway, we only reach the methods when the shortcut fails. As such we should probably just add type annotations to the methods.

floitsch avatar Jan 28 '22 11:01 floitsch