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

Error when property has same name as DU case #16760

Closed
wants to merge 10 commits into from

Conversation

edgarfgp
Copy link
Contributor

Description

Fixes #16646

Checklist

  • Test cases added

  • Performance benchmarks added in case of performance changes

  • Release notes entry updated:

    Please make sure to add an entry with short succinct description of the change as well as link to this pull request to the respective release notes file, if applicable.

    Release notes files:

    • If anything under src/Compiler has been changed, please make sure to make an entry in docs/release-notes/.FSharp.Compiler.Service/<version>.md, where <version> is usually "highest" one, e.g. 42.8.200
    • If language feature was added (i.e. LanguageFeatures.fsi was changed), please add it to docs/releae-notes/.Language/preview.md
    • If a change to FSharp.Core was made, please make sure to edit docs/release-notes/.FSharp.Core/<version>.md where version is "highest" one, e.g. 8.0.200.

    Information about the release notes entries format can be found in the documentation.
    Example:

    If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

Copy link
Contributor

❗ Release notes required

@edgarfgp,

Caution

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:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

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

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md No release notes found or release notes format is not correct

@edgarfgp edgarfgp closed this Feb 25, 2024
@edgarfgp edgarfgp reopened this Feb 25, 2024
@edgarfgp
Copy link
Contributor Author

edgarfgp commented Feb 26, 2024

Seems like I have some unrelated tests failing.
Failed TryGetRecentCheckResultsForFile called with snapshot returns cached result after ParseAndCheckFile(True) [240 ms] Error Message: System.Exception : no results from TryGetRecentCheckResultsForFile
cc @vzarytovskii FYI

@vzarytovskii
Copy link
Member

Seems like we I have some unrelated tests failing. Failed TryGetRecentCheckResultsForFile called with snapshot returns cached result after ParseAndCheckFile(True) [240 ms] Error Message: System.Exception : no results from TryGetRecentCheckResultsForFile cc @vzarytovskii FYI

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.

@vzarytovskii
Copy link
Member

#16766

# 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
Copy link
Contributor Author

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 defined
  • member 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

cc @vzarytovskii

Copy link
Member

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)?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psfinaki Im revisiting this here #17088

@edgarfgp edgarfgp closed this Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Unexpected FS0812 when property has same name as DU case
3 participants