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

Name resolution: don't search extension members in type abbreviations #16390

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap: Import.Impor
let pri = NextExtensionMethodPriority()

if g.langVersion.SupportsFeature(LanguageFeature.CSharpExtensionAttributeNotRequired) then
let csharpStyleExtensionMembers =
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || tcrefOfStaticClass.IsLocalRef then
let csharpStyleExtensionMembers =
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || (tcrefOfStaticClass.IsLocalRef && not tcrefOfStaticClass.IsTypeAbbrev) then
protectAssemblyExploration [] (fun () ->
let ty = generalizedTyconRef g tcrefOfStaticClass
GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,42 @@ type Bar =
|> withReferences [ fsharp ]

csharp |> compile |> shouldSucceed

[<Fact>]
let ``Abbreviated CSharp type with extensions`` () =
let csharp =
CSharp """
namespace CSharpLib {

public interface I
{
public int P { get; }
}

public static class Ext
{
public static void M(this I i)
{
}
}
}
"""
|> withName "CSLib"

let fsharp =
FSharp """
module Module

open CSharpLib

module M =
type Ext2 = CSharpLib.Ext

let f (i: I) =
i.M()
"""
|> withLangVersion80
|> withName "FSLib"
|> withReferences [ csharp ]

fsharp |> compile |> shouldSucceed