Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch errors #325

Open
haxscramper opened this issue Jan 26, 2021 · 2 comments
Open

Type mismatch errors #325

haxscramper opened this issue Jan 26, 2021 · 2 comments

Comments

@haxscramper
Copy link

haxscramper commented Jan 26, 2021

Current error outputs just dumps all possible overloads, without determining their validity in given context. When working on some high-level code, seeing 40+ overloads for add, when you just tried to append to let variable is insanely annoying.

By default, some mismatches are hidden, but particular logic is not entirely clear - it is possible to have one out of four overloads hidden in one case, but for mismatch on + you can get several screens worth of text.

Scored type mismatch listing

Possible solution would be to introduce score-based system for determining validity of each overload. Possible rules might include:

  • expected first argument to be var, but found immutable - high similarity score.
  • Unknown named argument, but close name exists - possible typo. Medium score.
  • First type is completely different - expected object, found proc (with MCS and missing variable it can happen quite easily) - negative similarity score.

Any other score rules - I just listed more obvious ones.

If all overload alternatives have very low score, enable additional heuristics for error suggestion.

Better formatting

Current way of formatting output AST also leaves a lot of room form improvement - providing optional colored suggestion, aligning function calls, arguments. This is partially related to #324 (as users might create own pretty-printers with extended heuristics), but the default implementation needs to be addressed too.

This is especially notable in case of callback type mismatches - differing noSideEffect, gcsafe annotations are not easily spotted. Providing tree-based diffing for types and emphasizing only mismatching parts would certainly help a lot.

In short - I think that errors like this are completely unacceptable, no matter how complex code is. Good formatting and basic AST coloring are the way to go for easy-to-understand error messages.

image

@haxscramper
Copy link
Author

Split into separate RFC from #322

@haxscramper
Copy link
Author

haxscramper commented Jan 26, 2021

I haven't mentioned tetrahedron of pain - static/generics/concept/types-in-macros - mainly because I don't have any concrete input on this topic, but I thing some other people do, so I decided to not introduce more noise in the discussion.

bors bot added a commit to nim-works/nimskull that referenced this issue Jan 16, 2022
94: Structured reports r=haxscramper a=haxscramper

Full rework of the compiler message handling pipeline. Remove old-style message generation that was based purely on strings that were formatted in-place, and instead implement structured logging where main compiler code only instantiates objects with required information.

This would allow to
- decouple error presentation logic from the semantic checking and other parts of the compiler. Added bonus: user-facing error messages can be improved much faster, since changes don't have to be propagated through the test suite each time.
- allow compilation reports to be printed out as a stream of S-expression or JSON lines
- Added bonus: user-facing error messages can be improved much faster, since changes don't have to be propagated through the test suite each time.

In addition to architectural improvements this PR also reorganizes and documents various error kinds. Whole thing has to be rewritten from the ground up, so RFCs like 
nim-lang/RFCs#323 nim-lang/RFCs#324 nim-lang/RFCs#325 will be implemented as a collateral

Decoupling of the data and presentation also allows to properly test compilation errors, warnings and hints generated by the compiler and finally untie compiler unit tests from the hardcoded string formatting in the semantic checking phase.

This PR is an orthogonal to the `nkError` project, and is only concerned with a *content* of the error report, while `nkError` is all about *presence* of errors during compilation. 

Co-authored-by: haxscramper <haxscramper@gmail.com>
bors bot added a commit to nim-works/nimskull that referenced this issue Jan 17, 2022
94: Structured reports r=haxscramper a=haxscramper

Full rework of the compiler message handling pipeline. Remove old-style message generation that was based purely on strings that were formatted in-place, and instead implement structured logging where main compiler code only instantiates objects with required information.

This would allow to
- decouple error presentation logic from the semantic checking and other parts of the compiler. Added bonus: user-facing error messages can be improved much faster, since changes don't have to be propagated through the test suite each time.
- allow compilation reports to be printed out as a stream of S-expression or JSON lines
- Added bonus: user-facing error messages can be improved much faster, since changes don't have to be propagated through the test suite each time.

In addition to architectural improvements this PR also reorganizes and documents various error kinds. Whole thing has to be rewritten from the ground up, so RFCs like 
nim-lang/RFCs#323 nim-lang/RFCs#324 nim-lang/RFCs#325 will be implemented as a collateral

Decoupling of the data and presentation also allows to properly test compilation errors, warnings and hints generated by the compiler and finally untie compiler unit tests from the hardcoded string formatting in the semantic checking phase.

This PR is an orthogonal to the `nkError` project, and is only concerned with a *content* of the error report, while `nkError` is all about *presence* of errors during compilation. 

Co-authored-by: haxscramper <haxscramper@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant