Skip to content

Commit 88911b9

Browse files
nelson-wubaronfel
authored andcommitted
Disallow attributes on type extensions (#7481)
* add test for feature * add error logic to typechecker * update strings * address comments * update tests
1 parent 8e044aa commit 88911b9

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/fsharp/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,7 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
14611461
3243,parsInvalidAnonRecdExpr,"Invalid anonymous record expression"
14621462
3244,parsInvalidAnonRecdType,"Invalid anonymous record type"
14631463
3245,tcCopyAndUpdateNeedsRecordType,"The input to a copy-and-update expression that creates an anonymous record must be either an anonymous record or a record"
1464+
3246,tcAugmentationsCannotHaveAttributes,"Attributes cannot be applied to type extensions."
14641465
3300,chkInvalidFunctionParameterType,"The parameter '%s' has an invalid type '%s'. This is not permitted by the rules of Common IL."
14651466
3301,chkInvalidFunctionReturnType,"The function or method has an invalid return type '%s'. This is not permitted by the rules of Common IL."
14661467
useSdkRefs,"Use reference assemblies for .NET framework references when available (Enabled by default)."

src/fsharp/TypeChecker.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16429,6 +16429,11 @@ module TcDeclarations =
1642916429
if not (isNil members) && tcref.IsTypeAbbrev then
1643016430
errorR(Error(FSComp.SR.tcTypeAbbreviationsCannotHaveAugmentations(), tyDeclRange))
1643116431

16432+
let (ComponentInfo (attributes, _, _, _, _, _, _, _)) = synTyconInfo
16433+
if not (List.isEmpty attributes) && (declKind = ExtrinsicExtensionBinding || declKind = IntrinsicExtensionBinding) then
16434+
let attributeRange = (List.head attributes).Range
16435+
error(Error(FSComp.SR.tcAugmentationsCannotHaveAttributes(), attributeRange))
16436+
1643216437
MutRecDefnsPhase2DataForTycon(tyconOpt, innerParent, declKind, tcref, baseValOpt, safeInitInfo, declaredTyconTypars, members, tyDeclRange, newslotsOK, fixupFinalAttrs))
1643316438

1643416439
// By now we've established the full contents of type definitions apart from their

0 commit comments

Comments
 (0)