Skip to content

Commit 9d36fda

Browse files
CopilotT-Gro
andcommitted
Add support for voption union cases in attribute arguments
This change allows ValueNone and ValueSome to be used as attribute argument values by recognizing union case expressions as valid constant expressions in attributes. Co-authored-by: T-Gro <[email protected]>
1 parent adc71bb commit 9d36fda

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Compiler/Checking/PostInferenceChecks.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,8 @@ and CheckAttribArgExpr cenv env expr =
19741974
| AttribBitwiseOrExpr g (arg1, arg2) ->
19751975
CheckAttribArgExpr cenv env arg1
19761976
CheckAttribArgExpr cenv env arg2
1977+
| Expr.Op (TOp.UnionCase _, _, args, _) ->
1978+
List.iter (CheckAttribArgExpr cenv env) args
19771979
| _ ->
19781980
if cenv.reportErrors then
19791981
errorR (Error (FSComp.SR.chkInvalidCustAttrVal(), expr.Range))

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10329,6 +10329,9 @@ let rec EvalAttribArgExpr suppressLangFeatureCheck (g: TcGlobals) (x: Expr) =
1032910329
| _ ->
1033010330
errorR (Error ( FSComp.SR.tastNotAConstantExpression(), x.Range))
1033110331
x
10332+
| Expr.Op (TOp.UnionCase _, _, _args, _) ->
10333+
// Union cases (like ValueNone, Some x) are valid constant expressions for attributes
10334+
x
1033210335
| _ ->
1033310336
errorR (Error ( FSComp.SR.tastNotAConstantExpression(), x.Range))
1033410337
x
@@ -10338,6 +10341,8 @@ and EvaledAttribExprEquality g e1 e2 =
1033810341
| Expr.Const (c1, _, _), Expr.Const (c2, _, _) -> c1 = c2
1033910342
| TypeOfExpr g ty1, TypeOfExpr g ty2 -> typeEquiv g ty1 ty2
1034010343
| TypeDefOfExpr g ty1, TypeDefOfExpr g ty2 -> typeEquiv g ty1 ty2
10344+
| Expr.Op (TOp.UnionCase (UnionCaseRef(tc1, nm1)), _, args1, _), Expr.Op (TOp.UnionCase (UnionCaseRef(tc2, nm2)), _, args2, _) ->
10345+
tyconRefEq g tc1 tc2 && nm1 = nm2 && (args1.Length = args2.Length) && List.forall2 (EvaledAttribExprEquality g) args1 args2
1034110346
| _ -> false
1034210347

1034310348
[<return: Struct>]

0 commit comments

Comments
 (0)