@@ -1203,11 +1203,13 @@ module MutRecBindingChecking =
1203
1203
if cenv.g.langVersion.SupportsFeature( LanguageFeature.CSharpExtensionAttributeNotRequired) then
1204
1204
tyconOpt
1205
1205
|> Option.map ( fun tycon ->
1206
- tryAddExtensionAttributeIfNotAlreadyPresent
1206
+ tryAddExtensionAttributeIfNotAlreadyPresentForType
1207
+ g
1207
1208
( fun tryFindExtensionAttribute ->
1208
1209
tycon.MembersOfFSharpTyconSorted
1209
1210
|> Seq.tryPick ( fun m -> tryFindExtensionAttribute m.Attribs)
1210
1211
)
1212
+ envForTycon.eModuleOrNamespaceTypeAccumulator
1211
1213
tycon
1212
1214
)
1213
1215
else
@@ -1437,7 +1439,25 @@ module MutRecBindingChecking =
1437
1439
1438
1440
let innerState = ( tpenv, envInstance, envStatic, envNonRec, generalizedRecBinds, preGeneralizationRecBinds, uncheckedRecBindsTable)
1439
1441
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
+
1441
1461
let defnBs = MutRecShape.Tycon ( TyconBindingsPhase2B( tyconOpt, tcref, defnBs))
1442
1462
let outerState = ( tpenv, generalizedRecBinds, preGeneralizationRecBinds, uncheckedRecBindsTable, envNonRec)
1443
1463
defnBs, outerState)
@@ -4536,16 +4556,20 @@ module TcDeclarations =
4536
4556
|> List.map ( function
4537
4557
| MutRecShape.Tycon ( Some tycon, bindings) ->
4538
4558
let tycon =
4539
- tryAddExtensionAttributeIfNotAlreadyPresent
4559
+ tryAddExtensionAttributeIfNotAlreadyPresentForType
4560
+ g
4540
4561
( fun tryFindExtensionAttribute ->
4541
4562
tycon.MembersOfFSharpTyconSorted
4542
4563
|> Seq.tryPick ( fun m -> tryFindExtensionAttribute m.Attribs)
4543
4564
)
4565
+ envFinal.eModuleOrNamespaceTypeAccumulator
4544
4566
tycon
4567
+
4545
4568
MutRecShape.Tycon ( Some tycon, bindings)
4546
4569
| MutRecShape.Module (( MutRecDefnsPhase2DataForModule( moduleOrNamespaceType, entity), env), shapes) ->
4547
4570
let entity =
4548
- tryAddExtensionAttributeIfNotAlreadyPresent
4571
+ tryAddExtensionAttributeIfNotAlreadyPresentForModule
4572
+ g
4549
4573
( fun tryFindExtensionAttribute ->
4550
4574
moduleOrNamespaceType.Value.AllValsAndMembers
4551
4575
|> Seq.filter( fun v -> v.IsModuleBinding)
@@ -4667,8 +4691,28 @@ module TcDeclarations =
4667
4691
let envForTycon = AddDeclaredTypars CheckForDuplicateTypars declaredTyconTypars envForDecls
4668
4692
let envForTycon = MakeInnerEnvForTyconRef envForTycon tcref ( declKind = ExtrinsicExtensionBinding)
4669
4693
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)
4671
4706
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
+ )
4672
4716
// Do this for each 'val' declaration in a module
4673
4717
( fun envForDecls ( containerInfo , valSpec ) ->
4674
4718
let tpenv = emptyUnscopedTyparEnv
@@ -5138,7 +5182,8 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
5138
5182
//
5139
5183
//[<System.Runtime.CompilerServices.Extension>]
5140
5184
//let PlusOne (a:int) = a + 1
5141
- tryAddExtensionAttributeIfNotAlreadyPresent
5185
+ tryAddExtensionAttributeIfNotAlreadyPresentForModule
5186
+ g
5142
5187
( fun tryFindExtensionAttribute ->
5143
5188
match moduleContents with
5144
5189
| ModuleOrNamespaceContents.TMDefs( defs) ->
0 commit comments