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

Fixes #14613 #14617

Merged
merged 9 commits into from
Jan 19, 2023
Merged

Fixes #14613 #14617

merged 9 commits into from
Jan 19, 2023

Conversation

vzarytovskii
Copy link
Member

@vzarytovskii vzarytovskii commented Jan 16, 2023

Fixes #14613 (an issue in preview version of F# which was introduced in #14263)

Adds another FindMemberFlag "strategy", which folds over type hierarchy bottom-to-top (from parent up) and discards all members if it detects that a non-virtual member with same signature hides virtual one.

@kerams @auduchinok if you have any more tests in mind, I'll gladly add it.

cc @edgarfgp

@vzarytovskii vzarytovskii requested a review from a team as a code owner January 16, 2023 16:25
Copy link
Contributor

@0101 0101 left a comment

Choose a reason for hiding this comment

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

If the tests pass it's probably good 👍

src/Compiler/Checking/InfoReader.fs Outdated Show resolved Hide resolved
@edgarfgp
Copy link
Contributor

@vzarytovskii We could add a tests where the virtual method was hidden ?

public class A
{
    public virtual void M4(string x) { }
}

public class B : A
{
    public new void M4() { }
}

type C =
    inherit B()

    override this.M4(x: string) = ()

@vzarytovskii
Copy link
Member Author

@vzarytovskii Vlad Zarytovskii FTE We could add a tests where the virtual method was hidden ?

public class A
{
    public virtual void M4(string x) { }
}

public class B : A
{
    public new void M4() { }
}

type C =
    inherit B()

    override this.M4(x: string) = ()

Shouldn't this be covered by the following existing one? M3 in B is hiding the one in A.

[<Fact>]
    let ``Virtual member was not found that corresponds to this override nested base class with lang version preview`` () =
        let CSLib =
            CSharp """
public class A
{
    public virtual void M1() { }
    public virtual void M2() { }
    public virtual void M3() { }
    public virtual void M4() { }
}

public class B : A
{
    public override void M1() { }
    public void M2() { }
    public new void M3() { }
    public new virtual void M4() { }
}
        """ |> withName "CSLib"

        let app =
            FSharp """
module ClassTests
type C() =
    inherit B()
    
    override this.M1() = ()
    override this.M2() = () // error expected
    override this.M3() = () // error expected
    override this.M4() = ()
    member this.M5() = ()
        """ |> withReferences [CSLib]
        app
        |> withLangVersionPreview
        |> compile
        |> shouldFail
        |> withDiagnostics [
            (Error 855, Line 7, Col 19, Line 7, Col 21, "No abstract or interface member was found that corresponds to this override")
            (Error 855, Line 8, Col 19, Line 8, Col 21, "No abstract or interface member was found that corresponds to this override")
        ]

@edgarfgp
Copy link
Contributor

edgarfgp commented Jan 16, 2023

@vzarytovskii Vlad Zarytovskii FTE We could add a tests where the virtual method was hidden ?

I think it will but I did not that add a test for the cases when the overload has one or more parameters . But Yeah in theory it will be covered with the previous tests

@vzarytovskii vzarytovskii marked this pull request as draft January 16, 2023 17:46
@vzarytovskii
Copy link
Member Author

@vzarytovskii

        Vlad Zarytovskii
        FTE Vlad Zarytovskii FTE We could add a tests where the virtual method was hidden ?

I think it will but I did not that add a test for the cases when the overload has one or more parameters . But Yeah in theory it will be covered with the previous tests

I've added couple of tests around overloads.

@vzarytovskii
Copy link
Member Author

I am a bit worried that I've missed some obvious (probably generic-related) overloads resolution for the new path

@edgarfgp
Copy link
Contributor

class C
{
    public virtual void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d) {}
}


class D : C
{
    public override void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d)
        where T1 : default
        where T3 : default
    {
        base.M(a, b, c, d);
    }
}

@vzarytovskii We can add a tests that consumes this generic overload ?

@vzarytovskii
Copy link
Member Author

class C
{
    public virtual void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d) {}
}


class D : C
{
    public override void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d)
        where T1 : default
        where T3 : default
    {
        base.M(a, b, c, d);
    }
}

@vzarytovskii We can add a tests that consumes this generic overload ?

Sure. What do w expect overload to be in F#? Just same generic method?

@edgarfgp
Copy link
Contributor

```fsharp
class C
{
    public virtual void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d) {}
}


class D : C
{
    public override void M<T1, T2, T3>(T1? a, T2 b, T1? c, T3? d)
        where T1 : default
        where T3 : default
    {
        base.M(a, b, c, d);
    }
}

@vzarytovskii We can add a tests that consumes this generic overload ?

Sure. What do w expect overload to be in F#? Just same generic method?

Yes

type X =
    inherit C

    override this.M(a, b, c, d) = ()

@vzarytovskii vzarytovskii marked this pull request as ready for review January 17, 2023 14:51
@vzarytovskii
Copy link
Member Author

I will merge this fix and add more tests in the separate PR

@vzarytovskii vzarytovskii merged commit 47a4241 into dotnet:main Jan 19, 2023
@vzarytovskii vzarytovskii deleted the fix-14613 branch January 19, 2023 16:28
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.

Unable to override overloaded mixed (non)virtual methods
6 participants