Fix enum constraints in recursive groups and improve constraint diagnostics (#14580) - #20454
Open
edgarfgp wants to merge 5 commits into
Open
Fix enum constraints in recursive groups and improve constraint diagnostics (#14580)#20454edgarfgp wants to merge 5 commits into
edgarfgp wants to merge 5 commits into
Conversation
Contributor
✅ No release notes required |
…garfgp/fsharp into fix/14580-enum-constraint-diagnostics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two problems with
enumconstraints. A bareenumconstraint gets a cryptic error that leaks an internal marker, and anenum<...>constraint checked against an enum of the same recursive group crashes with an internal error.Fixes #14580.
Before
After
The recursive group compiles, and a wrong underlying type is still reported:
Cause
The suffixes
(2)/(3)/(4)are in theparsUnexpectedIdentifierarguments inpars.fsyto tell the rules apart, and they ship in the message. Bareenumfalls into the same catch-all as any unknown identifier, so the parser now uses FS0699, which the checker already has for this.The internal error is a phase ordering problem. Phase1B gives an enum its kind with an empty field table, so
isEnumTyis true, but thevalue__field holding the underlying type is only added in Phase1G. Constraints checked in between, for abbreviations in Phase1E and inheritance in Phase1F, ask for an underlying type that does not exist yet.letbindings were unaffected because they are checked after Phase1G.SolveTypeIsEnumnow usestryUnderlyingTypeOfEnumTy, which returnsValueNonewhile the representation is being established, and re-queues the solve on the existing post inference check list. Nothing is skipped, so a wrong underlying type is still reported, in implementation and signature files.Making a bare
enumvalid would be a language change and needs an fslang suggestion first, so this PR keeps rejecting it and only fixes the message.