diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 831597c031a..e1eff2a2086 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -1461,6 +1461,7 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl 3243,parsInvalidAnonRecdExpr,"Invalid anonymous record expression" 3244,parsInvalidAnonRecdType,"Invalid anonymous record type" 3245,tcCopyAndUpdateNeedsRecordType,"The input to a copy-and-update expression that creates an anonymous record must be either an anonymous record or a record" +3246,tcAugmentationsCannotHaveAttributes,"Attributes cannot be applied to type extensions." 3300,chkInvalidFunctionParameterType,"The parameter '%s' has an invalid type '%s'. This is not permitted by the rules of Common IL." 3301,chkInvalidFunctionReturnType,"The function or method has an invalid return type '%s'. This is not permitted by the rules of Common IL." useSdkRefs,"Use reference assemblies for .NET framework references when available (Enabled by default)." diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 7610c4f209e..091b2f68738 100644 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -16429,6 +16429,11 @@ module TcDeclarations = if not (isNil members) && tcref.IsTypeAbbrev then errorR(Error(FSComp.SR.tcTypeAbbreviationsCannotHaveAugmentations(), tyDeclRange)) + let (ComponentInfo (attributes, _, _, _, _, _, _, _)) = synTyconInfo + if not (List.isEmpty attributes) && (declKind = ExtrinsicExtensionBinding || declKind = IntrinsicExtensionBinding) then + let attributeRange = (List.head attributes).Range + error(Error(FSComp.SR.tcAugmentationsCannotHaveAttributes(), attributeRange)) + MutRecDefnsPhase2DataForTycon(tyconOpt, innerParent, declKind, tcref, baseValOpt, safeInitInfo, declaredTyconTypars, members, tyDeclRange, newslotsOK, fixupFinalAttrs)) // By now we've established the full contents of type definitions apart from their diff --git a/src/fsharp/xlf/FSComp.txt.cs.xlf b/src/fsharp/xlf/FSComp.txt.cs.xlf index 7ff138f6adf..94cd285b69a 100644 --- a/src/fsharp/xlf/FSComp.txt.cs.xlf +++ b/src/fsharp/xlf/FSComp.txt.cs.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. Není definovaný obor názvů {0}. diff --git a/src/fsharp/xlf/FSComp.txt.de.xlf b/src/fsharp/xlf/FSComp.txt.de.xlf index 1645cfc2d52..32eb4893110 100644 --- a/src/fsharp/xlf/FSComp.txt.de.xlf +++ b/src/fsharp/xlf/FSComp.txt.de.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. Der Namespace "{0}" ist nicht definiert. diff --git a/src/fsharp/xlf/FSComp.txt.es.xlf b/src/fsharp/xlf/FSComp.txt.es.xlf index 279d16a7c90..59cd5ac6aca 100644 --- a/src/fsharp/xlf/FSComp.txt.es.xlf +++ b/src/fsharp/xlf/FSComp.txt.es.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. El espacio de nombres "{0}" no está definido. diff --git a/src/fsharp/xlf/FSComp.txt.fr.xlf b/src/fsharp/xlf/FSComp.txt.fr.xlf index 0be131277cd..13d12054f2b 100644 --- a/src/fsharp/xlf/FSComp.txt.fr.xlf +++ b/src/fsharp/xlf/FSComp.txt.fr.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. L'espace de noms '{0}' n'est pas défini. diff --git a/src/fsharp/xlf/FSComp.txt.it.xlf b/src/fsharp/xlf/FSComp.txt.it.xlf index 53ca4ca804e..2d75e7fd993 100644 --- a/src/fsharp/xlf/FSComp.txt.it.xlf +++ b/src/fsharp/xlf/FSComp.txt.it.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. Lo spazio dei nomi '{0}' non è definito. diff --git a/src/fsharp/xlf/FSComp.txt.ja.xlf b/src/fsharp/xlf/FSComp.txt.ja.xlf index 25ad9ef7015..085b1b5c0b7 100644 --- a/src/fsharp/xlf/FSComp.txt.ja.xlf +++ b/src/fsharp/xlf/FSComp.txt.ja.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. 名前空間 '{0}' が定義されていません。 diff --git a/src/fsharp/xlf/FSComp.txt.ko.xlf b/src/fsharp/xlf/FSComp.txt.ko.xlf index f1a4302d509..34e15943a00 100644 --- a/src/fsharp/xlf/FSComp.txt.ko.xlf +++ b/src/fsharp/xlf/FSComp.txt.ko.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. '{0}' 네임스페이스가 정의되지 않았습니다. diff --git a/src/fsharp/xlf/FSComp.txt.pl.xlf b/src/fsharp/xlf/FSComp.txt.pl.xlf index f50ce51d8dd..ca1578541e8 100644 --- a/src/fsharp/xlf/FSComp.txt.pl.xlf +++ b/src/fsharp/xlf/FSComp.txt.pl.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. Nie zdefiniowano przestrzeni nazw „{0}”. diff --git a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf index cf3fbbae234..2f4dd259360 100644 --- a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf +++ b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. O namespace '{0}' não está definido. diff --git a/src/fsharp/xlf/FSComp.txt.ru.xlf b/src/fsharp/xlf/FSComp.txt.ru.xlf index f4c4134fda1..00a7823fc27 100644 --- a/src/fsharp/xlf/FSComp.txt.ru.xlf +++ b/src/fsharp/xlf/FSComp.txt.ru.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. Пространство имен "{0}" не определено. diff --git a/src/fsharp/xlf/FSComp.txt.tr.xlf b/src/fsharp/xlf/FSComp.txt.tr.xlf index 216c29567d6..697fb5bbe03 100644 --- a/src/fsharp/xlf/FSComp.txt.tr.xlf +++ b/src/fsharp/xlf/FSComp.txt.tr.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. '{0}' ad alanı tanımlı değil. diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf index b2a9493d151..db8f678d525 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. 未定义命名空间“{0}”。 diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf index d9c19965864..e737e76c880 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf @@ -17,6 +17,11 @@ Algorithm '{0}' is not supported + + Attributes cannot be applied to type extensions. + Attributes cannot be applied to type extensions. + + The namespace '{0}' is not defined. 未定義命名空間 '{0}'。 diff --git a/tests/fsharp/Compiler/Language/TypeAttributeTests.fs b/tests/fsharp/Compiler/Language/TypeAttributeTests.fs new file mode 100644 index 00000000000..44a1cac08b7 --- /dev/null +++ b/tests/fsharp/Compiler/Language/TypeAttributeTests.fs @@ -0,0 +1,44 @@ +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Compiler.SourceCodeServices + +[] +module TypeAttributeTests = + + [] + let ``Attribute can be applied to type definition``() = + CompilerAssert.Pass + """ +[] +type Point = {x:int; y:int} + """ + [] + let ``Attribute cannot be applied to optional type extension``() = + CompilerAssert.TypeCheckSingleError + """ +open System + +[] +type String with + member this.test = 42 + """ + FSharpErrorSeverity.Error + 3246 + (4, 1, 4, 15) + "Attributes cannot be applied to type extensions." + + [] + let ``Attribute cannot be applied to intrinsic type extension``() = + CompilerAssert.TypeCheckSingleError + """ +type Point = {x:int; y:int} + +[] +type Point with + member this.test = 42 + """ + FSharpErrorSeverity.Error + 3246 + (4, 1, 4, 15) + "Attributes cannot be applied to type extensions." diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 1b1d3386ac5..fc1e8d0e4b3 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -55,6 +55,7 @@ +