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

Merged
merged 15 commits into from
Oct 25, 2024

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
Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>
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
@edgarfgp
Copy link
Contributor Author

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

@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.

@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 Updated following you suggestion. @abonie also suggested the same previously.

@vzarytovskii vzarytovskii disabled auto-merge October 25, 2024 12:03
@vzarytovskii vzarytovskii enabled auto-merge (squash) October 25, 2024 12:03
auto-merge was automatically disabled October 25, 2024 12:28

Head branch was pushed to by a user without write access

@auduchinok
Copy link
Member

@edgarfgp Thanks!

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.

5 participants