@@ -1203,11 +1203,13 @@ module MutRecBindingChecking =
12031203 if cenv.g.langVersion.SupportsFeature( LanguageFeature.CSharpExtensionAttributeNotRequired) then
12041204 tyconOpt
12051205 |> Option.map ( fun tycon ->
1206- tryAddExtensionAttributeIfNotAlreadyPresent
1206+ tryAddExtensionAttributeIfNotAlreadyPresentForType
1207+ g
12071208 ( fun tryFindExtensionAttribute ->
12081209 tycon.MembersOfFSharpTyconSorted
12091210 |> Seq.tryPick ( fun m -> tryFindExtensionAttribute m.Attribs)
12101211 )
1212+ envForTycon.eModuleOrNamespaceTypeAccumulator
12111213 tycon
12121214 )
12131215 else
@@ -1437,7 +1439,25 @@ module MutRecBindingChecking =
14371439
14381440 let innerState = ( tpenv, envInstance, envStatic, envNonRec, generalizedRecBinds, preGeneralizationRecBinds, uncheckedRecBindsTable)
14391441 Phase2BMember rbind.RecBindingInfo.Index, innerState)
1440-
1442+
1443+ let tyconOpt =
1444+ if not ( cenv.g.langVersion.SupportsFeature( LanguageFeature.CSharpExtensionAttributeNotRequired)) then
1445+ tyconOpt
1446+ else
1447+ // We need to redo this check, which already happened in TcMutRecBindings_Phase2A_CreateRecursiveValuesAndCheckArgumentPatterns
1448+ // Because the environment is being reset in the case of recursive modules.
1449+ tyconOpt
1450+ |> Option.map ( fun tycon ->
1451+ tryAddExtensionAttributeIfNotAlreadyPresentForType
1452+ g
1453+ ( fun tryFindExtensionAttribute ->
1454+ tycon.MembersOfFSharpTyconSorted
1455+ |> Seq.tryPick ( fun m -> tryFindExtensionAttribute m.Attribs)
1456+ )
1457+ envForTycon.eModuleOrNamespaceTypeAccumulator
1458+ tycon
1459+ )
1460+
14411461 let defnBs = MutRecShape.Tycon ( TyconBindingsPhase2B( tyconOpt, tcref, defnBs))
14421462 let outerState = ( tpenv, generalizedRecBinds, preGeneralizationRecBinds, uncheckedRecBindsTable, envNonRec)
14431463 defnBs, outerState)
@@ -4536,16 +4556,20 @@ module TcDeclarations =
45364556 |> List.map ( function
45374557 | MutRecShape.Tycon ( Some tycon, bindings) ->
45384558 let tycon =
4539- tryAddExtensionAttributeIfNotAlreadyPresent
4559+ tryAddExtensionAttributeIfNotAlreadyPresentForType
4560+ g
45404561 ( fun tryFindExtensionAttribute ->
45414562 tycon.MembersOfFSharpTyconSorted
45424563 |> Seq.tryPick ( fun m -> tryFindExtensionAttribute m.Attribs)
45434564 )
4565+ envFinal.eModuleOrNamespaceTypeAccumulator
45444566 tycon
4567+
45454568 MutRecShape.Tycon ( Some tycon, bindings)
45464569 | MutRecShape.Module (( MutRecDefnsPhase2DataForModule( moduleOrNamespaceType, entity), env), shapes) ->
45474570 let entity =
4548- tryAddExtensionAttributeIfNotAlreadyPresent
4571+ tryAddExtensionAttributeIfNotAlreadyPresentForModule
4572+ g
45494573 ( fun tryFindExtensionAttribute ->
45504574 moduleOrNamespaceType.Value.AllValsAndMembers
45514575 |> Seq.filter( fun v -> v.IsModuleBinding)
@@ -4667,8 +4691,28 @@ module TcDeclarations =
46674691 let envForTycon = AddDeclaredTypars CheckForDuplicateTypars declaredTyconTypars envForDecls
46684692 let envForTycon = MakeInnerEnvForTyconRef envForTycon tcref ( declKind = ExtrinsicExtensionBinding)
46694693
4670- TcTyconMemberSpecs cenv envForTycon ( TyconContainerInfo( innerParent, tcref, declaredTyconTypars, NoSafeInitInfo)) declKind tpenv members)
4694+ let vals , env = TcTyconMemberSpecs cenv envForTycon ( TyconContainerInfo( innerParent, tcref, declaredTyconTypars, NoSafeInitInfo)) declKind tpenv members
4695+ if not ( cenv.g.langVersion.SupportsFeature( LanguageFeature.CSharpExtensionAttributeNotRequired)) then
4696+ vals, env
4697+ else
4698+ // Check if any of the vals has the `[<Extension>]` attribute
4699+ // If this is the case, add it to the type in the env.
4700+ let extensionAttributeOnVals =
4701+ vals
4702+ |> List.tryPick ( fun v -> tryFindExtensionAttribute g v.Attribs)
4703+
4704+ let typeEntity =
4705+ envForTycon.eModuleOrNamespaceTypeAccumulator.Value.AllEntitiesByLogicalMangledName.TryFind( tcref.LogicalName)
46714706
4707+ match extensionAttributeOnVals, typeEntity with
4708+ | Some extensionAttribute, Some typeEntity ->
4709+ if Option.isNone ( tryFindExtensionAttribute g typeEntity.Attribs) then
4710+ typeEntity.entity_ attribs <- extensionAttribute :: typeEntity.Attribs
4711+ | _ -> ()
4712+
4713+ vals, env
4714+
4715+ )
46724716 // Do this for each 'val' declaration in a module
46734717 ( fun envForDecls ( containerInfo , valSpec ) ->
46744718 let tpenv = emptyUnscopedTyparEnv
@@ -5138,7 +5182,8 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
51385182 //
51395183 //[<System.Runtime.CompilerServices.Extension>]
51405184 //let PlusOne (a:int) = a + 1
5141- tryAddExtensionAttributeIfNotAlreadyPresent
5185+ tryAddExtensionAttributeIfNotAlreadyPresentForModule
5186+ g
51425187 ( fun tryFindExtensionAttribute ->
51435188 match moduleContents with
51445189 | ModuleOrNamespaceContents.TMDefs( defs) ->
0 commit comments