essential-contributions / pint

Pint, the constraint-based programming language for declarative blockchains
Apache License 2.0
17 stars 3 forks source link

Reduce the error output from type checking a little bit more. #830

Closed otrho closed 2 months ago

otrho commented 2 months ago

While looking through the type checker there were a couple of things I wasn't 100% happy with.

Previously, to reduce error message noise, we would return an incorrect inferred type when an expression type was known but invalid and an error had been emitted. This was to smooth out the flow and avoid a bunch of superfluous checks, but I don't think it's great for the type checker to be saying 'um, well, this expression is bogus but here's a type I made up, just go with it'. 🙂

So in those cases I've replaced the pretend type with Type::Error. But this re-introduces some legitimate noise, but also stops errors declaring they were expecting incorrect types. So to avoid the noise I've added a bunch of extra checks -- especially around binary operators. If either the LHS or RHS type is error then it will not emit more type errors. There are also checks so that we don't ever say 'expecting Unknown' or 'expecting Error' or 'found Unknown' or 'found Error'.

I also changed the span for constraint decl type errors since it was highlighting the whole decl as needing to be bool when really only the RHS should be.