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

Better ranges for implicit inherit error reporting. #17893

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Oct 16, 2024

Description

Better ranges for implicit Inherit error reporting.

Before

Screenshot 2024-10-16 at 18 39 28

Screenshot 2024-10-16 at 18 40 26
Screenshot 2024-10-16 at 18 40 40

After

type ClassA() = class end

type ClassB() = class end

type ClassC() = class end

type Class() =
    inherit ClassA()
    inherit ClassB()
            ^^^^^^
    inherit ClassC()
            ^^^^^^

Checklist

  • Test cases added
  • Release notes entry updated

Copy link
Contributor

github-actions bot commented Oct 16, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

@edgarfgp edgarfgp changed the title Better ranges for implicit Inherit error reporting. Better ranges for implicit inherit error reporting. Oct 16, 2024
@edgarfgp edgarfgp marked this pull request as ready for review October 17, 2024 05:28
@edgarfgp edgarfgp requested a review from a team as a code owner October 17, 2024 05:28
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Thanks Edgar!

@edgarfgp edgarfgp requested a review from T-Gro October 18, 2024 16:14
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 959, Line 10, Col 5, Line 10, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration")
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually want both these errors? I mean 959 and 932 for each additional inherit?

Is there ever a case where there's going to be a 932 without a corresponding 959? If not, is 932 actually useful?

And if we do want both, I'd argue 932 should be thrown only once regardless of how many extra inherit specifications there are and its range should actually be line 8 in this example above, so like it was before:

type Class() =
     ^^^^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abonie

Do we actually want both these errors? I mean 959 and 932 for each additional inherit?

I guess arguably we do not need 959 as 932 will cover the cases for having multiple inherit. Should we get ride of 959 ?

Personally I think showing the specific ranges for inherit is more clear and guides the user toward removing rather than just using the type definition.

@edgarfgp
Copy link
Contributor Author

Please wait for https://github.com/dotnet/fsharp/pull/17905/files to be merged first.

Copy link
Member

Choose a reason for hiding this comment

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

Marker to not merge this accidentally.

@auduchinok
Copy link
Member

@edgarfgp Thanks for your contribution! I'm sorry to say this, but I disagree with this change. I'll try to explain it on this example:

type T() =
    inherit A()
    inherit B()

I expect that there's an error about multiple inherit members. That means that the actual source of the errors are the inherit members themselves, not the type names inside of them. Moving the error to the inherited type name may say to many people that there's no error with the inherit member itself, and there's something wrong with the inherited type usage.

@auduchinok
Copy link
Member

Could you please also add tests for multiple base interfaces, if there're none?

type I =
    inherit IA
    inherit IB

@edgarfgp
Copy link
Contributor Author

@edgarfgp Thanks for your contribution! I'm sorry to say this, but I disagree with this change. I'll try to explain it on this example:

type T() =
    inherit A()
    inherit B()

I expect that there's an error about multiple inherit members. That means that the actual source of the errors are the inherit members themselves, not the type names inside of them. Moving the error to the inherited type name may say to many people that there's no error with the inherit member itself, and there's something wrong with the inherited type usage.

@auduchinok No need to apologise for disagreeing. This is a collaborative effort and Im glad that you are reviewing my PRs :)

So is the following what you would expect ?

[<Fact>]
    let ``Types cannot inherit from multiple concrete types.`` () =
        Fsx """
type ClassA() = class end

type ClassB() = class end

type ClassC() = class end

type Class() =
    inherit ClassA()
    inherit ClassB()
    inherit ClassC()
        """
        |> typecheck
        |> shouldFail
        |> withDiagnostics [
            (Error 959, Line 10, Col 5, Line 10, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration")
            (Error 959, Line 11, Col 5, Line 11, Col 12, "Type definitions may only have one 'inherit' specification and it must be the first declaration")
            (Error 932, Line 10, Col 13, Line 10, Col 19, "Types cannot inherit from multiple concrete types")
            (Error 932, Line 11, Col 13, Line 11, Col 19, "Types cannot inherit from multiple concrete types")
        ]

@auduchinok
Copy link
Member

@edgarfgp More or less, yes. I'd probably prefer the 932 errors to be on the Class type name, not on the inherit members.

@edgarfgp
Copy link
Contributor Author

@edgarfgp More or less, yes. I'd probably prefer the 932 errors to be on the Class type name, not on the inherit members.

Humm. But using the type name and not the inherit range makes it look like multiple inherits are allowed(Unless you hover the type name). I would prefer to be use the accurate range.

@auduchinok
Copy link
Member

Humm. But using the type name and not the inherit range makes it look like multiple inherits are allowed

Hm, it should not, since 959 errors are still going to be on the inherit members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants