Skip to content

Commit 86a2cf0

Browse files
CopilotT-Gro
andcommitted
Fix issue #19074: Support voption with optional parameter syntax (?x=)
Revert incorrect attribute changes and fix the actual issue where using ?x=ValueNone or ?x=ValueSome with optional parameters expecting voption was failing with type mismatch. The fix allows the type inference to determine whether to use option or voption based on the parameter type when the language feature is enabled. Co-authored-by: T-Gro <[email protected]>
1 parent 9d36fda commit 86a2cf0

File tree

3 files changed

+1
-8
lines changed

3 files changed

+1
-8
lines changed

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9934,7 +9934,7 @@ and TcMethodApplication_SplitSynArguments
99349934
// named optional arguments should always have option type
99359935
// STRUCT OPTIONS: if we allow struct options as optional arguments then we should relax this and rely
99369936
// on later inference to work out if this is a struct option or ref option
9937-
let ty = if isOpt then mkOptionTy denv.g ty else ty
9937+
let ty = if isOpt && not (denv.g.langVersion.SupportsFeature LanguageFeature.SupportValueOptionsAsOptionalParameters) then mkOptionTy denv.g ty else ty
99389938
nm, isOpt, x, ty, x.Range)
99399939

99409940
(Some (unnamedCurriedCallerArgs, namedCurriedCallerArgs), None, exprTy)

src/Compiler/Checking/PostInferenceChecks.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,8 +1974,6 @@ 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
19791977
| _ ->
19801978
if cenv.reportErrors then
19811979
errorR (Error (FSComp.SR.chkInvalidCustAttrVal(), expr.Range))

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10329,9 +10329,6 @@ 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
1033510332
| _ ->
1033610333
errorR (Error ( FSComp.SR.tastNotAConstantExpression(), x.Range))
1033710334
x
@@ -10341,8 +10338,6 @@ and EvaledAttribExprEquality g e1 e2 =
1034110338
| Expr.Const (c1, _, _), Expr.Const (c2, _, _) -> c1 = c2
1034210339
| TypeOfExpr g ty1, TypeOfExpr g ty2 -> typeEquiv g ty1 ty2
1034310340
| 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
1034610341
| _ -> false
1034710342

1034810343
[<return: Struct>]

0 commit comments

Comments
 (0)