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

Incorrect compiler error message for out-of-order members #17962

Open
brianberns opened this issue Nov 6, 2024 · 4 comments
Open

Incorrect compiler error message for out-of-order members #17962

brianberns opened this issue Nov 6, 2024 · 4 comments

Comments

@brianberns
Copy link

Repro steps

Compile the snippet below:

type MyType =
    { MyField : string }
    member this.Length = this.MyProperty.Length
    member this.MyProperty = this.MyField

Expected behavior

Either:

  • Program compiles successfully, because order of members is irrelevant.
  • Program fails to compile with a correct error message, because order of members is relevant.

The expected error message in the second case would be:

The type 'MyType' does not define the field, constructor or member 'MyProperty'

Actual behavior

Compiler error message on Length property:

Program.fs(3,26): error FS0072: Lookup on object of indeterminate type...

This is an incorrect error message, because specifying the type of this does not fix the problem:

member this.Length = (this : MyType).MyProperty.Length   // "Lookup on object of indeterminate type"

Note that Visual Studio suggests the following fix instead, which also does not work:

member (this: MyType).Length = this.MyProperty.Length   // "Unexpected symbol '.' in member definition"

Known workarounds

Swap the order of the two members.

Related information

Microsoft (R) F# Compiler version 12.8.401.0 for F# 8.0

@github-actions github-actions bot added this to the Backlog milestone Nov 6, 2024
@edgarfgp
Copy link
Contributor

edgarfgp commented Nov 6, 2024

Adding type annotation seems to also work

type MyType =
    { MyField : string }
    member this.Length = this.MyProperty.Length
    member this.MyProperty: string = this.MyField
                          ^^^^^^^^

@brianberns
Copy link
Author

Oh, that's interesting and not what I expected. I thought the problem was that this has an indeterminate type, but it's actually that MyProperty has an indeterminate type.

@vzarytovskii
Copy link
Member

Might use some more precise ranges, yeah.

@edgarfgp
Copy link
Contributor

edgarfgp commented Nov 6, 2024

Might use some more precise ranges, yeah.

This will be fixed when I finish #17556. Just need to fix some Editor tests(AutoCompletion etc..) that are really annoying if you do not have a windows machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

3 participants