-
Notifications
You must be signed in to change notification settings - Fork 790
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
Error when property has same name as DU case #16760
Conversation
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
Seems like I have some unrelated tests failing. |
I have seen this one today as well. It's a transparent compiler tests, I will disable it and create an issue for re-enabling. |
# Conflicts: # tests/fsharpqa/Source/Conformance/InferenceProcedures/NameResolution/Misc/E_ClashingIdentifiersDU02.fs
|
||
let onlyIdX (ids: MyId list) = ids |> List.choose _.IdX | ||
let onlyIdA (ids: MyId list) = ids |> List.choose _.IdA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psfinaki This now raises an error message if you accessing to a member that has the same name as the union case. reusing FS0023
(Error 23, Line 17, Col 51, Line 17, Col 56, "The member 'IdA' can not be defined because the name 'IdA' clashes with the union case 'IdA' in this type or module")
I propose we update the error message so it can be used in both cases ie
member
is definedmember
is used
Avoiding having to create another error number and message. Maybe
-
The member 'IdA' can not be used because 'IdA' clashes with the union case 'IdA' in this type or module
-
The name 'IdA' can not be used because 'IdA' clashes with the union case 'IdA' in this type or module
-
The member 'IdA' can not be defined or accessed because the name 'IdA' clashes with the union case 'IdA' in this type or module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but why not having both errors here? As in,
type MyId =
| IdA of int
| IdB of string
member this.IdA =
match this with
| IdA x -> Some x
| _ -> None
let onlyIdA (ids: MyId list) = ids |> List.choose _.IdA
...would produce both
FS0023 The member 'IdA' can not be defined because the name 'IdA' clashes with the union case 'IdA' in this type or module
and
FS0812 The syntax 'expr.id' may only be used with record labels, properties and fields
,
as if they were independent (which they kind of are)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the existing logic uses error(Error(..))
which prevents the analysis to continue so even if we try to add both they would cancel each other. Ideally it would be good to change to use errorR
but will require rewriting of pat of the analysis. The best we can do for now is to reuse FS0023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean I probably misunderstand something here - why cannot/shouldn't we fix the error recovery in this case instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not that we can't. But it will required updating/splitting the upstream analysis to make it work as error
returns exn -> 'T
and errorR
returns exn -> unit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you feel adventurous we can maybe pair on this, maybe in an AmplifyingF# session :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context: This is the relevant piece of code that will needs updating https://github.com/dotnet/fsharp/blob/f29ce0aef9b70bfef03ef7466ec823e449bb864b/src/Compiler/Checking/CheckExpressions.fs#L9270C5-L9270C21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I just believe this can be an opportunity to fix the underlying issue rather than patch the symptome. But that's just my opinion 👀
Otherwise, "The member 'IdA' can not be defined or accessed" is something I would pick out of the options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well at the very least I would give a try and report some progress :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Fixes #16646
Checklist
Test cases added
Performance benchmarks added in case of performance changes
Release notes entry updated: