-
Notifications
You must be signed in to change notification settings - Fork 789
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
Fix for #83 (improve constraint error message) #16304
Conversation
This includes - An addition of field "source" to TraitConstraintInfo / TTrait in TypedTree.fs/fsi - Code in CompilerImports.fs which, after import, adds the sources to all constraints - New error messages, including the constraint source, in ConstraintSolver.fs - The error messages in FSComp.txt - A new test in MemberConstraints.fs - 29 adaptations b.o. the new field in TTrait in 9 files
/run xlf |
Co-authored-by: Martin521 <29605222+Martin521@users.noreply.github.com>
Hey @Martin521 - thanks for taking this long-standing issue! :) I know there is a discussion in the related ticket - my opinion is that whatever we do will be better than the current situation. That said, for me even having I see that the message in FSComp is generic for types and operators so for now I would appreciate just adding a few more test cases that are expected to produce the same error, so that we can see a bigger picture. |
@psfinaki - thanks for your feedback!
I will do that. I will also respond (tomorrow) to your other remarks, but in the ticket. |
AFAIU, this would require infrastructure for API authors, and adjusting FSharp.Core to use it; the infrastructure would allow to give customized error message on members with constraints, given predicate on the passed / infered type arguments, to deliver a custom message. IMO, this is out of scope in just trying to improve the constraint not matching error, which should, unless the infrastructure & special condition that it would detect in API, always be displayed, in order to give the full picture. |
I personally disagree with that. It doesn't have to be either/or. It should be both - a simple message as well as bunch of details. We don't need to simplify messages in sake of simplifying them. But rather extend them. @DedSec256 and @auduchinok may have some opinions here. |
No yeah for sure we shouldn't overhaul the compiler just in order to make this usecase clear.
... is definitely a valid approach. |
Thanks @psfinaki for asking for more examples and the broader picture. This made me realize that the picture is broader indeed. I will continue with implementation (including test cases) once the discussion on the ticket is converging. |
since the second error it is introducing is not related to methods on enums and is difficult to verify.
This is ready. Also note that the extended error message only appears when the constraint source (the operator or method or function that has the constraint typar) is imported. Doing the same while that source is in your own project is more difficult, but also deemed to be not needed, because both the language guide and the spec say that creating member constraints is "not intended for common use". |
/azp run |
Commenter does not have sufficient privileges for PR 16304 in repo dotnet/fsharp |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Thanks, let's see how it looks in IDEs, and get feedback from people. |
* upstream/main: (166 commits) typo in foldBack summary (dotnet#16453) Fix for dotnet#83 (improve constraint error message) (dotnet#16304) Name resolution: resolve interfaces in expressions (dotnet#15660) AddExplicitReturnType refactoring (dotnet#16077) Disabling 2 tests: running for too long, causing CI timeouts Improve value restriction error message dotnet#1103 (dotnet#15877) Parens: Keep parens for non-identical infix operator pairs with same precedence (dotnet#16372) More release note entries (dotnet#16438) Using Ordinal is both faster and more correct as our intent is to do … (dotnet#16439) merge (dotnet#16427) Optimize empty string compares (dotnet#16435) Checker: recover on unresolved type in 'inherit' member (dotnet#16429) Release notes proposal (dotnet#16377) [main] Update dependencies from dotnet/source-build-reference-packages (dotnet#16411) Allow usage of [<TailCall>] with older FSharp.Core package versions (dotnet#16373) Parser: recover on unfinished 'as' patterns (dotnet#16404) Parens: Keep parens in method calls in dot-lambdas (dotnet#16395) Checker: check unfinished obj expression inside computations (dotnet#16413) Added default dotnet-tools + additional tasks to launch them (dotnet#16409) make `remarks` and `returns` visible in quick info (dotnet#16417) ...
This fix for #83 includes