Skip to content

Commit 24208f0

Browse files
authored
Fix access checking for properies setters in attribute arguments (#18581)
1 parent 9720080 commit 24208f0

17 files changed

+126
-2
lines changed

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11399,7 +11399,12 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
1139911399

1140011400
let mkAttribExpr e =
1140111401
AttribExpr(e, EvalLiteralExprOrAttribArg g e)
11402-
11402+
11403+
let checkPropSetterAttribAccess m (pinfo: PropInfo) =
11404+
let setterMeth = pinfo.SetterMethod
11405+
if not <| IsTypeAndMethInfoAccessible cenv.amap m ad ad setterMeth then
11406+
errorR(Error (FSComp.SR.tcPropertyCannotBeSetPrivateSetter(pinfo.PropertyName), m))
11407+
1140311408
let namedAttribArgMap =
1140411409
attributeAssignedNamedItems |> List.map (fun (CallerNamedArg(id, CallerArg(callerArgTy, m, isOpt, callerArgExpr))) ->
1140511410
if isOpt then error(Error(FSComp.SR.tcOptionalArgumentsCannotBeUsedInCustomAttribute(), m))
@@ -11411,6 +11416,7 @@ and TcAttributeEx canFail (cenv: cenv) (env: TcEnv) attrTgt attrEx (synAttr: Syn
1141111416
| Item.Property (info = [pinfo]) ->
1141211417
if not pinfo.HasSetter then
1141311418
errorR(Error(FSComp.SR.tcPropertyCannotBeSet0(), m))
11419+
checkPropSetterAttribAccess m pinfo
1141411420
id.idText, true, pinfo.GetPropertyType(cenv.amap, m)
1141511421
| Item.ILField finfo ->
1141611422
CheckILFieldInfoAccessible g cenv.amap m ad finfo

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
15261526
3245,tcCopyAndUpdateNeedsRecordType,"The input to a copy-and-update expression that creates an anonymous record must be either an anonymous record or a record"
15271527
3246,tcAugmentationsCannotHaveAttributes,"Attributes cannot be applied to type extensions."
15281528
3247,couldNotLoadDependencyManagerExtension,"The dependency manager extension %s could not be loaded. Message: %s"
1529+
3248,tcPropertyCannotBeSetPrivateSetter,"Property '%s' cannot be set because the setter is private"
15291530
3250,expressionHasNoName,"Expression does not have a name."
15301531
3251,chkNoFirstClassNameOf,"Using the 'nameof' operator as a first-class function value is not permitted."
15311532
3252,tcIllegalByrefsInOpenTypeDeclaration,"Byref types are not allowed in an open type declaration."

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)