Report a proper error for a bare 'enum' constraint (#14580) - #20454
Open
edgarfgp wants to merge 3 commits into
Open
Report a proper error for a bare 'enum' constraint (#14580)#20454edgarfgp wants to merge 3 commits into
edgarfgp wants to merge 3 commits into
Conversation
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
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
A bare
enumconstraint gets a cryptic error that leaks an internal marker, instead of saying what the constraint should look like.Fixes #14580.
Before
After
Cause
Two small defects in the constraint rules of
pars.fsy:parsUnexpectedIdentifierarguments have(2)/(3)/(4)suffixes to tell the rules apart, and they end up in the user-facing message.enumfalls into the same catch-all as any unknown identifier. The checker already has the right message for this (FS0699, localized), so the parser now uses it.About the original report: the repro there uses a bare
'T : enum, which since F# 8 is a parse error in every context (module recmakes no difference), so that spelling stops before type checking and this PR makes the rejection say why:The internal error itself is not fixed here. With the valid
enum<int>spelling it still happens on main, as @T-Gro reported in #14580 (comment):An
andgroup behaves the same way, and removing the recursion compiles. Phase1B gives an enum itsTFSharpEnumkind with an empty field table, soisEnumTyis already true whilevalue__is only added by Phase1G, and a constraint checked in between (abbreviations in Phase1E) asks for an underlying type that does not exist yet. So #14580 should stay open after this PR, which only covers the diagnostics.Accepting bare
enumagain, as F# 7 accidentally did via the self-constraint fallback, would be a language change and needs an fslang suggestion first.