@@ -378,6 +378,8 @@ let ImplicitlyOpenOwnNamespace tcSink g amap scopem enclosingNamespacePath (env:
378378
379379exception NotUpperCaseConstructor of range : range
380380
381+ exception NotUpperCaseConstructorWithoutRQA of range : range
382+
381383let CheckNamespaceModuleOrTypeName ( g : TcGlobals ) ( id : Ident ) =
382384 // type names '[]' etc. are used in fslib
383385 if not g.compilingFSharpCore && id.idText.IndexOfAny IllegalCharactersInTypeAndNamespaceNames <> - 1 then
@@ -453,16 +455,21 @@ module TcRecdUnionAndEnumDeclarations =
453455 // Bind other elements of type definitions (constructors etc.)
454456 //-------------------------------------------------------------------------
455457
456- let CheckUnionCaseName ( cenv : cenv ) ( id : Ident ) =
458+ let CheckUnionCaseName ( cenv : cenv ) ( id : Ident ) hasRQAAttribute =
457459 let g = cenv.g
458460 let name = id.idText
459461 if name = " Tags" then
460462 errorR( Error( FSComp.SR.tcUnionCaseNameConflictsWithGeneratedType( name, " Tags" ), id.idRange))
461463
462464 CheckNamespaceModuleOrTypeName g id
463465
464- if not ( String.isLeadingIdentifierCharacterUpperCase name) && name <> opNameCons && name <> opNameNil then
465- errorR( NotUpperCaseConstructor( id.idRange))
466+ if g.langVersion.SupportsFeature( LanguageFeature.LowercaseDUWhenRequireQualifiedAccess) then
467+
468+ if not ( String.isLeadingIdentifierCharacterUpperCase name) && not hasRQAAttribute && name <> opNameCons && name <> opNameNil then
469+ errorR( NotUpperCaseConstructorWithoutRQA( id.idRange))
470+ else
471+ if not ( String.isLeadingIdentifierCharacterUpperCase name) && name <> opNameCons && name <> opNameNil then
472+ errorR( NotUpperCaseConstructor( id.idRange))
466473
467474 let ValidateFieldNames ( synFields : SynField list , tastFields : RecdField list ) =
468475 let seen = Dictionary()
@@ -479,13 +486,13 @@ module TcRecdUnionAndEnumDeclarations =
479486 | _ ->
480487 seen.Add( f.LogicalName, sf))
481488
482- let TcUnionCaseDecl ( cenv : cenv ) env parent thisTy thisTyInst tpenv ( SynUnionCase ( Attributes synAttrs , SynIdent ( id , _ ), args , xmldoc , vis , m , _ )) =
489+ let TcUnionCaseDecl ( cenv : cenv ) env parent thisTy thisTyInst tpenv hasRQAAttribute ( SynUnionCase ( Attributes synAttrs , SynIdent ( id , _ ), args , xmldoc , vis , m , _ )) =
483490 let g = cenv.g
484491 let attrs = TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs // the attributes of a union case decl get attached to the generated "static factory" method
485492 let vis , _ = ComputeAccessAndCompPath env None m vis None parent
486493 let vis = CombineReprAccess parent vis
487494
488- CheckUnionCaseName cenv id
495+ CheckUnionCaseName cenv id hasRQAAttribute
489496
490497 let rfields , recordTy =
491498 match args with
@@ -526,8 +533,8 @@ module TcRecdUnionAndEnumDeclarations =
526533 let xmlDoc = xmldoc.ToXmlDoc( true , Some names)
527534 Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis
528535
529- let TcUnionCaseDecls cenv env parent ( thisTy : TType ) thisTyInst tpenv unionCases =
530- let unionCasesR = unionCases |> List.map ( TcUnionCaseDecl cenv env parent thisTy thisTyInst tpenv)
536+ let TcUnionCaseDecls ( cenv : cenv ) env ( parent : ParentRef ) ( thisTy : TType ) ( thisTyInst : TypeInst ) hasRQAAttribute tpenv unionCases =
537+ let unionCasesR = unionCases |> List.map ( TcUnionCaseDecl cenv env parent thisTy thisTyInst tpenv hasRQAAttribute )
531538 unionCasesR |> CheckDuplicates ( fun uc -> uc.Id) " union case"
532539
533540 let TcEnumDecl cenv env parent thisTy fieldTy ( SynEnumCase ( attributes = Attributes synAttrs; ident= SynIdent( id,_); value= v; xmlDoc= xmldoc; range= m)) =
@@ -3188,7 +3195,9 @@ module EstablishTypeDefinitionCores =
31883195
31893196 structLayoutAttributeCheck false
31903197 noAllowNullLiteralAttributeCheck()
3191- TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName
3198+
3199+ let hasRQAAttribute = HasFSharpAttribute cenv.g cenv.g.attrib_ RequireQualifiedAccessAttribute tycon.Attribs
3200+ TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName hasRQAAttribute
31923201 let unionCase = Construct.NewUnionCase unionCaseName [] thisTy [] XmlDoc.Empty tycon.Accessibility
31933202 writeFakeUnionCtorsToSink [ unionCase ]
31943203 Construct.MakeUnionRepr [ unionCase ], None, NoSafeInitInfo
@@ -3219,8 +3228,9 @@ module EstablishTypeDefinitionCores =
32193228 noAbstractClassAttributeCheck()
32203229 noAllowNullLiteralAttributeCheck()
32213230 structLayoutAttributeCheck false
3222- let unionCases = TcRecdUnionAndEnumDeclarations.TcUnionCaseDecls cenv envinner innerParent thisTy thisTyInst tpenv unionCases
3223-
3231+
3232+ let hasRQAAttribute = HasFSharpAttribute cenv.g cenv.g.attrib_ RequireQualifiedAccessAttribute tycon.Attribs
3233+ let unionCases = TcRecdUnionAndEnumDeclarations.TcUnionCaseDecls cenv envinner innerParent thisTy thisTyInst hasRQAAttribute tpenv unionCases
32243234 if tycon.IsStructRecordOrUnionTycon && unionCases.Length > 1 then
32253235 let fieldNames = [ for uc in unionCases do for ft in uc.FieldTable.TrueInstanceFieldsAsList do yield ft.LogicalName ]
32263236 if fieldNames |> List.distinct |> List.length <> fieldNames.Length then
0 commit comments