From b8aaf2d272ef537c4da40938147e416d376bba29 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 11 Jul 2022 20:18:51 +0100 Subject: [PATCH] Allow lower-case DU cases when RequireQualifiedAccess is specified (#13432) * Allow lower-case DU cases when RequireQualifiedAccess is specified * Fix PR suggestions and Add more testing * Protect feature under preview version * Add a NotUpperCaseConstructorWithoutRQA warning to be raised in lang version preview * Fix formatting --- src/Compiler/Checking/CheckDeclarations.fs | 30 ++++++---- src/Compiler/Checking/CheckDeclarations.fsi | 2 + src/Compiler/Driver/CompilerDiagnostics.fs | 5 ++ src/Compiler/FSComp.txt | 1 + src/Compiler/FSStrings.resx | 3 + src/Compiler/Facilities/LanguageFeatures.fs | 3 + src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ++ src/Compiler/xlf/FSStrings.cs.xlf | 5 ++ src/Compiler/xlf/FSStrings.de.xlf | 5 ++ src/Compiler/xlf/FSStrings.es.xlf | 5 ++ src/Compiler/xlf/FSStrings.fr.xlf | 5 ++ src/Compiler/xlf/FSStrings.it.xlf | 5 ++ src/Compiler/xlf/FSStrings.ja.xlf | 5 ++ src/Compiler/xlf/FSStrings.ko.xlf | 5 ++ src/Compiler/xlf/FSStrings.pl.xlf | 5 ++ src/Compiler/xlf/FSStrings.pt-BR.xlf | 5 ++ src/Compiler/xlf/FSStrings.ru.xlf | 5 ++ src/Compiler/xlf/FSStrings.tr.xlf | 5 ++ src/Compiler/xlf/FSStrings.zh-Hans.xlf | 5 ++ src/Compiler/xlf/FSStrings.zh-Hant.xlf | 5 ++ .../E_LowercaseWhenRequireQualifiedAccess.fsx | 22 +++++++ .../LowercaseWhenRequireQualifiedAccess.fsx | 44 ++++++++++++++ .../Conformance/UnionTypes/UnionTypes.fs | 58 +++++++++++++++++++ 36 files changed, 289 insertions(+), 10 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_LowercaseWhenRequireQualifiedAccess.fsx create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/LowercaseWhenRequireQualifiedAccess.fsx diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 9fd052bdd4b..cc7de71eceb 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -378,6 +378,8 @@ let ImplicitlyOpenOwnNamespace tcSink g amap scopem enclosingNamespacePath (env: exception NotUpperCaseConstructor of range: range +exception NotUpperCaseConstructorWithoutRQA of range: range + let CheckNamespaceModuleOrTypeName (g: TcGlobals) (id: Ident) = // type names '[]' etc. are used in fslib if not g.compilingFSharpCore && id.idText.IndexOfAny IllegalCharactersInTypeAndNamespaceNames <> -1 then @@ -453,7 +455,7 @@ module TcRecdUnionAndEnumDeclarations = // Bind other elements of type definitions (constructors etc.) //------------------------------------------------------------------------- - let CheckUnionCaseName (cenv: cenv) (id: Ident) = + let CheckUnionCaseName (cenv: cenv) (id: Ident) hasRQAAttribute = let g = cenv.g let name = id.idText if name = "Tags" then @@ -461,8 +463,13 @@ module TcRecdUnionAndEnumDeclarations = CheckNamespaceModuleOrTypeName g id - if not (String.isLeadingIdentifierCharacterUpperCase name) && name <> opNameCons && name <> opNameNil then - errorR(NotUpperCaseConstructor(id.idRange)) + if g.langVersion.SupportsFeature(LanguageFeature.LowercaseDUWhenRequireQualifiedAccess) then + + if not (String.isLeadingIdentifierCharacterUpperCase name) && not hasRQAAttribute && name <> opNameCons && name <> opNameNil then + errorR(NotUpperCaseConstructorWithoutRQA(id.idRange)) + else + if not (String.isLeadingIdentifierCharacterUpperCase name) && name <> opNameCons && name <> opNameNil then + errorR(NotUpperCaseConstructor(id.idRange)) let ValidateFieldNames (synFields: SynField list, tastFields: RecdField list) = let seen = Dictionary() @@ -479,13 +486,13 @@ module TcRecdUnionAndEnumDeclarations = | _ -> seen.Add(f.LogicalName, sf)) - let TcUnionCaseDecl (cenv: cenv) env parent thisTy thisTyInst tpenv (SynUnionCase(Attributes synAttrs, SynIdent(id, _), args, xmldoc, vis, m, _)) = + let TcUnionCaseDecl (cenv: cenv) env parent thisTy thisTyInst tpenv hasRQAAttribute (SynUnionCase(Attributes synAttrs, SynIdent(id, _), args, xmldoc, vis, m, _)) = let g = cenv.g let attrs = TcAttributes cenv env AttributeTargets.UnionCaseDecl synAttrs // the attributes of a union case decl get attached to the generated "static factory" method let vis, _ = ComputeAccessAndCompPath env None m vis None parent let vis = CombineReprAccess parent vis - CheckUnionCaseName cenv id + CheckUnionCaseName cenv id hasRQAAttribute let rfields, recordTy = match args with @@ -526,8 +533,8 @@ module TcRecdUnionAndEnumDeclarations = let xmlDoc = xmldoc.ToXmlDoc(true, Some names) Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis - let TcUnionCaseDecls cenv env parent (thisTy: TType) thisTyInst tpenv unionCases = - let unionCasesR = unionCases |> List.map (TcUnionCaseDecl cenv env parent thisTy thisTyInst tpenv) + let TcUnionCaseDecls (cenv: cenv) env (parent: ParentRef) (thisTy: TType) (thisTyInst: TypeInst) hasRQAAttribute tpenv unionCases = + let unionCasesR = unionCases |> List.map (TcUnionCaseDecl cenv env parent thisTy thisTyInst tpenv hasRQAAttribute) unionCasesR |> CheckDuplicates (fun uc -> uc.Id) "union case" 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 = structLayoutAttributeCheck false noAllowNullLiteralAttributeCheck() - TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName + + let hasRQAAttribute = HasFSharpAttribute cenv.g cenv.g.attrib_RequireQualifiedAccessAttribute tycon.Attribs + TcRecdUnionAndEnumDeclarations.CheckUnionCaseName cenv unionCaseName hasRQAAttribute let unionCase = Construct.NewUnionCase unionCaseName [] thisTy [] XmlDoc.Empty tycon.Accessibility writeFakeUnionCtorsToSink [ unionCase ] Construct.MakeUnionRepr [ unionCase ], None, NoSafeInitInfo @@ -3219,8 +3228,9 @@ module EstablishTypeDefinitionCores = noAbstractClassAttributeCheck() noAllowNullLiteralAttributeCheck() structLayoutAttributeCheck false - let unionCases = TcRecdUnionAndEnumDeclarations.TcUnionCaseDecls cenv envinner innerParent thisTy thisTyInst tpenv unionCases - + + let hasRQAAttribute = HasFSharpAttribute cenv.g cenv.g.attrib_RequireQualifiedAccessAttribute tycon.Attribs + let unionCases = TcRecdUnionAndEnumDeclarations.TcUnionCaseDecls cenv envinner innerParent thisTy thisTyInst hasRQAAttribute tpenv unionCases if tycon.IsStructRecordOrUnionTycon && unionCases.Length > 1 then let fieldNames = [ for uc in unionCases do for ft in uc.FieldTable.TrueInstanceFieldsAsList do yield ft.LogicalName ] if fieldNames |> List.distinct |> List.length <> fieldNames.Length then diff --git a/src/Compiler/Checking/CheckDeclarations.fsi b/src/Compiler/Checking/CheckDeclarations.fsi index c4590557ede..631e9fb5812 100644 --- a/src/Compiler/Checking/CheckDeclarations.fsi +++ b/src/Compiler/Checking/CheckDeclarations.fsi @@ -76,3 +76,5 @@ val CheckOneSigFile: Cancellable exception NotUpperCaseConstructor of range: range + +exception NotUpperCaseConstructorWithoutRQA of range: range diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index fba0a064091..f3537b7bbc0 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -124,6 +124,7 @@ let GetRangeOfDiagnostic (diagnostic: PhasedDiagnostic) = | LetRecCheckedAtRuntime m | UpperCaseIdentifierInPattern m | NotUpperCaseConstructor m + | NotUpperCaseConstructorWithoutRQA m | RecursiveUseCheckedAtRuntime (_, _, m) | LetRecEvaluatedOutOfOrder (_, _, _, m) | DiagnosticWithText (_, _, m) @@ -270,6 +271,7 @@ let GetDiagnosticNumber (diagnostic: PhasedDiagnostic) = | UseOfAddressOfOperator _ -> 51 | DefensiveCopyWarning _ -> 52 | NotUpperCaseConstructor _ -> 53 + | NotUpperCaseConstructorWithoutRQA _ -> 53 | TypeIsImplicitlyAbstract _ -> 54 // 55 cannot be reused | DeprecatedThreadStaticBindingWarning _ -> 56 @@ -435,6 +437,7 @@ let ErrorFromApplyingDefault2E () = Message("ErrorFromApplyingDefault2", "") let ErrorsFromAddingSubsumptionConstraintE () = Message("ErrorsFromAddingSubsumptionConstraint", "%s%s%s") let UpperCaseIdentifierInPatternE () = Message("UpperCaseIdentifierInPattern", "") let NotUpperCaseConstructorE () = Message("NotUpperCaseConstructor", "") +let NotUpperCaseConstructorWithoutRQAE () = Message("NotUpperCaseConstructorWithoutRQA", "") let FunctionExpectedE () = Message("FunctionExpected", "") let BakedInMemberConstraintNameE () = Message("BakedInMemberConstraintName", "%s") let BadEventTransformationE () = Message("BadEventTransformation", "") @@ -771,6 +774,8 @@ let OutputPhasedErrorR (os: StringBuilder) (diagnostic: PhasedDiagnostic) (canSu | NotUpperCaseConstructor _ -> os.AppendString(NotUpperCaseConstructorE().Format) + | NotUpperCaseConstructorWithoutRQA _ -> os.AppendString(NotUpperCaseConstructorWithoutRQAE().Format) + | ErrorFromAddingConstraint (_, e, _) -> OutputExceptionR os e #if !NO_TYPEPROVIDERS diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index a6ce206cc8f..97e24679878 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1543,6 +1543,7 @@ featureStructActivePattern,"struct representation for active patterns" featureRelaxWhitespace2,"whitespace relaxation v2" featureReallyLongList,"list literals of any size" featureErrorOnDeprecatedRequireQualifiedAccess,"give error on deprecated access of construct with RequireQualifiedAccess attribute" +featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQualifiedAccess attribute" 3353,fsiInvalidDirective,"Invalid directive '#%s %s'" 3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." 3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation." diff --git a/src/Compiler/FSStrings.resx b/src/Compiler/FSStrings.resx index bf1c66b0f29..51f172fbbea 100644 --- a/src/Compiler/FSStrings.resx +++ b/src/Compiler/FSStrings.resx @@ -1107,4 +1107,7 @@ internal error: {0} + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + \ No newline at end of file diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index a0033a5d2b7..77b93032baa 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -49,6 +49,7 @@ type LanguageFeature = | DelegateTypeNameResolutionFix | ReallyLongLists | ErrorOnDeprecatedRequireQualifiedAccess + | LowercaseDUWhenRequireQualifiedAccess /// LanguageVersion management type LanguageVersion(versionText) = @@ -111,6 +112,7 @@ type LanguageVersion(versionText) = LanguageFeature.BetterExceptionPrinting, previewVersion LanguageFeature.ReallyLongLists, previewVersion LanguageFeature.ErrorOnDeprecatedRequireQualifiedAccess, previewVersion + LanguageFeature.LowercaseDUWhenRequireQualifiedAccess, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -210,6 +212,7 @@ type LanguageVersion(versionText) = | LanguageFeature.DelegateTypeNameResolutionFix -> FSComp.SR.featureDelegateTypeNameResolutionFix () | LanguageFeature.ReallyLongLists -> FSComp.SR.featureReallyLongList () | LanguageFeature.ErrorOnDeprecatedRequireQualifiedAccess -> FSComp.SR.featureErrorOnDeprecatedRequireQualifiedAccess () + | LanguageFeature.LowercaseDUWhenRequireQualifiedAccess -> FSComp.SR.featureLowercaseDUWhenRequireQualifiedAccess () /// Get a version string associated with the given feature. member _.GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index ec884903b49..8227c947c77 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -39,6 +39,7 @@ type LanguageFeature = | DelegateTypeNameResolutionFix | ReallyLongLists | ErrorOnDeprecatedRequireQualifiedAccess + | LowercaseDUWhenRequireQualifiedAccess /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 2982b373922..f006f4b4879 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -192,6 +192,11 @@ rozhraní s vícenásobným obecným vytvářením instancí + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Revize kompatibility ML diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index cd9d6d81bb8..bcff666cca2 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -192,6 +192,11 @@ Schnittstellen mit mehrfacher generischer Instanziierung + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML-Kompatibilitätsrevisionen diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index f833bc6e76c..f0b34cd199e 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -192,6 +192,11 @@ interfaces con creación de instancias genéricas múltiples + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Revisiones de compatibilidad de ML diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index c949833a13a..e1faaa3ee52 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -192,6 +192,11 @@ interfaces avec plusieurs instanciations génériques + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Réviseurs de compatibilité ML diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index a9b2e133bde..bc3b6d77268 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -192,6 +192,11 @@ interfacce con più creazioni di istanze generiche + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Revisioni della compatibilità di Ml diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index d0637747c7a..f82dbf9c798 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -192,6 +192,11 @@ 複数のジェネリックのインスタンス化を含むインターフェイス + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML 互換性のリビジョン diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index fbbfdfbf306..1095e6c1729 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -192,6 +192,11 @@ 여러 제네릭 인스턴스화가 포함된 인터페이스 + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML 호환성 개정 diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index fbfb4f7e730..e5ad0012774 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -192,6 +192,11 @@ interfejsy z wieloma ogólnymi wystąpieniami + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Poprawki dotyczące zgodności Machine Learning diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 83b76374d27..35f58279210 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -192,6 +192,11 @@ interfaces com várias instanciações genéricas + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Revisões de compatibilidade de ML diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 93db1f6740a..d6d6e210791 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -192,6 +192,11 @@ интерфейсы с множественным универсальным созданием экземпляра + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions Редакции совместимости ML diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index acff017e25a..5440ee40f47 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -192,6 +192,11 @@ birden çok genel örnek oluşturma içeren arabirimler + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML uyumluluk düzeltmeleri diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 778f26de5e3..c9f007f023c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -192,6 +192,11 @@ 具有多个泛型实例化的接口 + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML 兼容性修订 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 81e0c44f38b..d9ad22c51f4 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -192,6 +192,11 @@ 具有多個泛型具現化的介面 + + Allow lowercase DU when RequireQualifiedAccess attribute + Allow lowercase DU when RequireQualifiedAccess attribute + + ML compatibility revisions ML 相容性修訂 diff --git a/src/Compiler/xlf/FSStrings.cs.xlf b/src/Compiler/xlf/FSStrings.cs.xlf index 924659eb22a..849a9018ef5 100644 --- a/src/Compiler/xlf/FSStrings.cs.xlf +++ b/src/Compiler/xlf/FSStrings.cs.xlf @@ -7,6 +7,11 @@ Nejméně jedna informační zpráva v načteném souboru\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' symbol ..^ diff --git a/src/Compiler/xlf/FSStrings.de.xlf b/src/Compiler/xlf/FSStrings.de.xlf index 9462806409e..79176e0e2f1 100644 --- a/src/Compiler/xlf/FSStrings.de.xlf +++ b/src/Compiler/xlf/FSStrings.de.xlf @@ -7,6 +7,11 @@ Mindestens eine Informationsmeldung in der geladenen Datei.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' Symbol "..^" diff --git a/src/Compiler/xlf/FSStrings.es.xlf b/src/Compiler/xlf/FSStrings.es.xlf index b4b8b4531e4..8b09a7c5903 100644 --- a/src/Compiler/xlf/FSStrings.es.xlf +++ b/src/Compiler/xlf/FSStrings.es.xlf @@ -7,6 +7,11 @@ Uno o más mensajes informativos en el archivo cargado.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' símbolo "..^" diff --git a/src/Compiler/xlf/FSStrings.fr.xlf b/src/Compiler/xlf/FSStrings.fr.xlf index 53e4eb6cff4..f88d8e7182b 100644 --- a/src/Compiler/xlf/FSStrings.fr.xlf +++ b/src/Compiler/xlf/FSStrings.fr.xlf @@ -7,6 +7,11 @@ Un ou plusieurs messages d’information dans le fichier chargé.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' symbole '..^' diff --git a/src/Compiler/xlf/FSStrings.it.xlf b/src/Compiler/xlf/FSStrings.it.xlf index d8cf6e9c21e..e46a3cb54d6 100644 --- a/src/Compiler/xlf/FSStrings.it.xlf +++ b/src/Compiler/xlf/FSStrings.it.xlf @@ -7,6 +7,11 @@ Uno o più messaggi informativi nel file caricato.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' simbolo '..^' diff --git a/src/Compiler/xlf/FSStrings.ja.xlf b/src/Compiler/xlf/FSStrings.ja.xlf index ad32096733b..b0a149427b1 100644 --- a/src/Compiler/xlf/FSStrings.ja.xlf +++ b/src/Compiler/xlf/FSStrings.ja.xlf @@ -7,6 +7,11 @@ 読み込まれたファイル内の 1 つ以上の情報メッセージ。\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' シンボル '..^' diff --git a/src/Compiler/xlf/FSStrings.ko.xlf b/src/Compiler/xlf/FSStrings.ko.xlf index 8e112d8d28c..da9ee85444d 100644 --- a/src/Compiler/xlf/FSStrings.ko.xlf +++ b/src/Compiler/xlf/FSStrings.ko.xlf @@ -7,6 +7,11 @@ 로드된 파일에 하나 이상의 정보 메시지가 있습니다.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' 기호 '..^' diff --git a/src/Compiler/xlf/FSStrings.pl.xlf b/src/Compiler/xlf/FSStrings.pl.xlf index fe6c8536f87..f89d330d272 100644 --- a/src/Compiler/xlf/FSStrings.pl.xlf +++ b/src/Compiler/xlf/FSStrings.pl.xlf @@ -7,6 +7,11 @@ Jeden lub więcej komunikatów informacyjnych w załadowanym pliku.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' symbol „..^” diff --git a/src/Compiler/xlf/FSStrings.pt-BR.xlf b/src/Compiler/xlf/FSStrings.pt-BR.xlf index 8dc8c546ffc..a6f597c97aa 100644 --- a/src/Compiler/xlf/FSStrings.pt-BR.xlf +++ b/src/Compiler/xlf/FSStrings.pt-BR.xlf @@ -7,6 +7,11 @@ Uma ou mais mensagens informativas no arquivo carregado.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' símbolo '..^' diff --git a/src/Compiler/xlf/FSStrings.ru.xlf b/src/Compiler/xlf/FSStrings.ru.xlf index 6979fe42d9f..310b7437a2e 100644 --- a/src/Compiler/xlf/FSStrings.ru.xlf +++ b/src/Compiler/xlf/FSStrings.ru.xlf @@ -7,6 +7,11 @@ Одно или несколько информационных сообщений в загруженном файле.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' символ "..^" diff --git a/src/Compiler/xlf/FSStrings.tr.xlf b/src/Compiler/xlf/FSStrings.tr.xlf index 54328fdea3f..c5cbc423360 100644 --- a/src/Compiler/xlf/FSStrings.tr.xlf +++ b/src/Compiler/xlf/FSStrings.tr.xlf @@ -7,6 +7,11 @@ Yüklenen dosyada bir veya daha fazla bilgi mesajı.\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' '..^' sembolü diff --git a/src/Compiler/xlf/FSStrings.zh-Hans.xlf b/src/Compiler/xlf/FSStrings.zh-Hans.xlf index 95130a6391f..be3604df4bf 100644 --- a/src/Compiler/xlf/FSStrings.zh-Hans.xlf +++ b/src/Compiler/xlf/FSStrings.zh-Hans.xlf @@ -7,6 +7,11 @@ 加载文件 .\n 中有一条或多条信息性消息 + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' 符号 "..^" diff --git a/src/Compiler/xlf/FSStrings.zh-Hant.xlf b/src/Compiler/xlf/FSStrings.zh-Hant.xlf index 5ff1442b5c3..67e6c25370e 100644 --- a/src/Compiler/xlf/FSStrings.zh-Hant.xlf +++ b/src/Compiler/xlf/FSStrings.zh-Hant.xlf @@ -7,6 +7,11 @@ 已載入檔案中的一或多個資訊訊息。\n + + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute + + symbol '..^' 符號 '..^' diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_LowercaseWhenRequireQualifiedAccess.fsx b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_LowercaseWhenRequireQualifiedAccess.fsx new file mode 100644 index 00000000000..a7e7a928e36 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/E_LowercaseWhenRequireQualifiedAccess.fsx @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + + + + +type DU1 = | ``not.allowed`` + +type DU2 = ``not.allowed`` + +[] +type DU3 = | ``not.allowed`` + +[] +type DU4 = ``not.allowed`` + +type DU5 = | a + +type DU6 = a + +type du1 = du1 of string + +type du2 = | du2 of string \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/LowercaseWhenRequireQualifiedAccess.fsx b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/LowercaseWhenRequireQualifiedAccess.fsx new file mode 100644 index 00000000000..e9080c19964 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/LowercaseWhenRequireQualifiedAccess.fsx @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + + + + +[] +type DU1 = + | a + | b + | c + +[] +type DU2 = + | a of int + | B of string + | C + +[] +type DU3 = | a + +[] +type DU4 = a + +[] +type du1 = du1 of string + +[] +type du2 = | du2 of string + +let a = DU1.a +let b = du2.du2 +let c = DU2.a(1) +let d = du2.du2("du2") +let e = du1.du1("du1") + +let f du1 = + match du1 with + | DU1.a -> () + | DU1.b -> () + | DU1.c -> () + +f DU1.c + + diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs index 1e27322bfbd..39f4fac3804 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/UnionTypes/UnionTypes.fs @@ -509,6 +509,64 @@ module UnionTypes = |> verifyCompileAndRun |> shouldSucceed + //SOURCE=LowercaseWhenRequireQualifiedAccess.fsx # LowercaseWhenRequireQualifiedAccess.fsx + [] + let ``LowercaseWhenRequireQualifiedAccess_fs in langversion 6`` compilation = + compilation + |> withLangVersion60 + |> verifyCompile + |> shouldFail + + //SOURCE=LowercaseWhenRequireQualifiedAccess.fsx # LowercaseWhenRequireQualifiedAccess.fsx + [] + let ``LowercaseWhenRequireQualifiedAccess_fs in preview`` compilation = + compilation + |> withLangVersionPreview + |> verifyCompileAndRun + |> shouldSucceed + + //SOURCE=E_LowercaseWhenRequireQualifiedAccess.fsx # E_LowercaseWhenRequireQualifiedAccess.fsx + [] + let ``E_LowercaseWhenRequireQualifiedAccess_fs in preview`` compilation = + compilation + |> withLangVersionPreview + |> verifyCompile + |> shouldFail + |> withDiagnostics [ + (Error 883, Line 6, Col 14, Line 6, Col 29, "Invalid namespace, module, type or union case name"); + (Error 53, Line 6, Col 14, Line 6, Col 29, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute"); + (Error 883, Line 8, Col 12, Line 8, Col 27, "Invalid namespace, module, type or union case name"); + (Error 53, Line 8, Col 12, Line 8, Col 27, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute"); + (Error 883, Line 11, Col 14, Line 11, Col 29, "Invalid namespace, module, type or union case name"); + (Error 883, Line 14, Col 12, Line 14, Col 27, "Invalid namespace, module, type or union case name"); + (Error 53, Line 16, Col 14, Line 16, Col 15, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute"); + (Error 53, Line 18, Col 12, Line 18, Col 13, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute"); + (Error 53, Line 20, Col 12, Line 20, Col 15, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute"); + (Error 53, Line 22, Col 14, Line 22, Col 17, "Lowercase discriminated union cases are only allowed when using RequireQualifiedAccess attribute") + ] + + //SOURCE=E_LowercaseWhenRequireQualifiedAccess.fsx # E_LowercaseWhenRequireQualifiedAccess.fsx + [] + let ``E_LowercaseWhenRequireQualifiedAccess_fs in langversion 6`` compilation = + compilation + |> withLangVersion60 + |> verifyCompile + |> shouldFail + |> withDiagnostics [ + (Error 883, Line 6, Col 14, Line 6, Col 29, "Invalid namespace, module, type or union case name"); + (Error 53, Line 6, Col 14, Line 6, Col 29, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 883, Line 8, Col 12, Line 8, Col 27, "Invalid namespace, module, type or union case name"); + (Error 53, Line 8, Col 12, Line 8, Col 27, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 883, Line 11, Col 14, Line 11, Col 29, "Invalid namespace, module, type or union case name"); + (Error 53, Line 11, Col 14, Line 11, Col 29, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 883, Line 14, Col 12, Line 14, Col 27, "Invalid namespace, module, type or union case name"); + (Error 53, Line 14, Col 12, Line 14, Col 27, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 53, Line 16, Col 14, Line 16, Col 15, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 53, Line 18, Col 12, Line 18, Col 13, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 53, Line 20, Col 12, Line 20, Col 15, "Discriminated union cases and exception labels must be uppercase identifiers"); + (Error 53, Line 22, Col 14, Line 22, Col 17, "Discriminated union cases and exception labels must be uppercase identifiers") + ] + //SOURCE=W_GenericFunctionValuedStaticProp02.fs SCFLAGS="--test:ErrorRanges --warnaserror-" # W_GenericFunctionValuedStaticProp02.fs [] let ``W_GenericFunctionValuedStaticProp02_fs`` compilation =