From cff239b0bbd71be290f9eb20a02ecfcae51b2a4c Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Tue, 5 Dec 2023 18:40:04 +0100 Subject: [PATCH 1/2] Name resolution: don't search extension members in type abbreviations --- src/Compiler/Checking/NameResolution.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index fd6550983c5..d4456d6ce54 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -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 From 563be802e31a72eb7c12b39dcd133b12bb54493a Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Tue, 5 Dec 2023 19:04:27 +0100 Subject: [PATCH 2/2] Add test --- .../Language/ExtensionMethodTests.fs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/ExtensionMethodTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/ExtensionMethodTests.fs index 817b33a43d6..510ac830ae4 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/ExtensionMethodTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/ExtensionMethodTests.fs @@ -609,3 +609,42 @@ type Bar = |> withReferences [ fsharp ] csharp |> compile |> shouldSucceed + + [] + 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