@@ -511,14 +511,6 @@ module TcRecdUnionAndEnumDeclarations =
511511
512512 let TcUnionCaseDecl ( cenv : cenv ) env parent thisTy thisTyInst tpenv hasRQAAttribute ( SynUnionCase ( Attributes synAttrs , SynIdent ( id , _ ), args , xmldoc , vis , m , _ )) =
513513 let g = cenv.g
514- let attrs =
515- // The attributes of a union case decl get attached to the generated "static factory" method
516- // Enforce that the union-cases can only be targeted by attributes with AttributeTargets.Method
517- if g.langVersion.SupportsFeature( LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations) then
518- TcAttributes cenv env AttributeTargets.Method synAttrs
519- else
520- TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs
521-
522514 let vis , _ = ComputeAccessAndCompPath g env None m vis None parent
523515 let vis = CombineReprAccess parent vis
524516
@@ -571,6 +563,23 @@ module TcRecdUnionAndEnumDeclarations =
571563
572564 let checkXmlDocs = cenv.diagnosticOptions.CheckXmlDocs
573565 let xmlDoc = xmldoc.ToXmlDoc( checkXmlDocs, Some names)
566+ let attrs =
567+ (*
568+ The attributes of a union case decl get attached to the generated "static factory" method.
569+ Enforce union-cases AttributeTargets:
570+ - AttributeTargets.Method
571+ type SomeUnion =
572+ | Case1 of int // Compiles down to a static method
573+ - AttributeTargets.Property
574+ type SomeUnion =
575+ | Case1 // Compiles down to a static property
576+ *)
577+ if g.langVersion.SupportsFeature( LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations) then
578+ let target = if rfields.IsEmpty then AttributeTargets.Property else AttributeTargets.Method
579+ TcAttributes cenv env target synAttrs
580+ else
581+ TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs
582+
574583 Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis
575584
576585 let TcUnionCaseDecls ( cenv : cenv ) env ( parent : ParentRef ) ( thisTy : TType ) ( thisTyInst : TypeInst ) hasRQAAttribute tpenv unionCases =
0 commit comments