Don't show cascaded type errors (1)
The expression
Int a = 1 / "x"
will show two type errors at the moment.This should only give an error on
1 / "x"
.A fix would involve looking at failing dependencies.
Submitted by Daco Harkes on 11 March 2014 at 14:40Plus(x, y) : y-ty where x : x-ty and y : y-ty and x-ty == y-ty else error $[Type mismatch: expected [x-ty] got [y-ty] in Addition] on y only if x-ty and y-ty succeed
Issue Log
Related to cascaded type errors is if a failed name resolution triggers a type error;
Int x = y
with y undefined.Multiple messages: - Type mismatch: expected Int got in Derivation - Unresolved reference
Note: “expected Int got in Derivation” shows an empty string on the failed type between got and in.
This error is annoying when TS is actually being used in a language.
You can catch this in the message prettyprinter. For example, I’m using this code in Green Marl:
// Source: https://yellowgrass.org/issue/TS/2#showText416aa302157a6f217b48ca594cb7e9f9 pp-message-top = origin-track-forced((id, strip-annos; pp-message; html-escape)) pp-message = map(pp-preprocess(fail);pp-message-part); concat-strings // note the cascaded strategy can be something like !"<dep-fail>" for a placeholder message to go through, // or fail to keep the message from being printed pp-preprocess(cascaded) = [] < cascaded + try(\[a] -> a\) pp-message-part = not(is-list); (is-string <+ pp-partial-Green-Marl-string <+ (strip-annos; write-to-string)) pp-message-part = is-list; map(pp-message-part);separate-by(|", ") => l*; !["[",l*,"]"];concat-strings html-escape = string-replace(|"&","&");string-replace(|"<","<");string-replace(|">",">")
Nice.
Yesterday there was a talk by Juriaan Hage on error diagnosis with constraint based typing.
Basically specifying priorities on the constraints (determining which constraint is solved first) and when an unsolvable constraint is encountered you display the message tied to that constraint: theelse error
fromTS
. Then you drop that constraint and continue solving, and repeat the process if you find another unsolvable constraint.There are two ways of adding priorities to constraints:
- intra-rule: the constraint per type rule are ordered + inter-rule: phases: doing all type signatures before expressions - paper, another paper
- regular tree expressions: specify constraints over more than a single rule at the time (with recursion) - Juriaans work recently
Log in to post comments