flofriday / Moose

🐐 A new fun programming language
MIT License
6 stars 1 forks source link

Typechecker gets confused and cannot recover #48

Closed flofriday closed 1 year ago

flofriday commented 1 year ago
Screenshot 2022-09-17 at 08 42 20

Often only the first error from the typechecker is relevant as the typechecker gets confused and prints errors that only arise from the first one.

I don't know how to handle that best, cause we probably would need to introduce a new intermediate type called Undetermined or Confused so that the parser ignores all expressions where one type is undertermined.

Jozott00 commented 1 year ago

Yes, we would have to catch errors in the assignment and need to store r with an error type or something and every time we use r we check if it is of the error type and throw an error type exception which does not get printed to the user. I think that's the way how swift handles this (you can try it yourself by assigning something wrong to an variable and then inspect its type in the ide. It will say <<error type>>.

I think it wouldn't be too hard to implement, since it does only require changes in the assignment of identifier and in the typecker visit of an identifier.

flofriday commented 1 year ago

Yeah sounds good.

flofriday commented 1 year ago

So I am currently trying to solve this but it is not tottally easy to figure out where and why the parser gets confused.

flofriday commented 1 year ago

The typechecker now has internal errortype which it assigns to experssions it cannot reason about.

If such an experssion is assigned to an variable it will also get an error type. At this point further usage of this variable will get an free pass and will not get typechecked again.

Therefore only the original sinn will be highlighted and not errors that also originate from the original mistake.

This makes the reported errors of much higher quality.