@@ -9723,10 +9723,12 @@ let EvalArithBinOp (opInt8, opInt16, opInt32, opInt64, opUInt8, opUInt16, opUInt
97239723 with :? System.OverflowException -> error ( Error ( FSComp.SR.tastConstantExpressionOverflow(), m))
97249724
97259725// See also PostTypeCheckSemanticChecks.CheckAttribArgExpr, which must match this precisely
9726- let rec EvalAttribArgExpr g x =
9726+ let rec EvalAttribArgExpr ( g : TcGlobals ) x =
97279727 let ignore ( _x : 'a ) = Unchecked.defaultof< 'a>
97289728 let ignore2 ( _x : 'a ) ( _y : 'a ) = Unchecked.defaultof< 'a>
97299729
9730+ let arithmeticInLiteralsEnabled = g.langVersion.SupportsFeature LanguageFeature.ArithmeticInLiterals
9731+
97309732 match x with
97319733
97329734 // Detect standard constants
@@ -9774,28 +9776,32 @@ let rec EvalAttribArgExpr g x =
97749776 match v1, v2 with
97759777 | Expr.Const ( Const.String x1, m, ty), Expr.Const ( Const.String x2, _, _) ->
97769778 Expr.Const ( Const.String ( x1 + x2), m, ty)
9777- | Expr.Const ( Const.Char x1, m, ty), Expr.Const ( Const.Char x2, _, _) ->
9779+ | Expr.Const ( Const.Char x1, m, ty), Expr.Const ( Const.Char x2, _, _) when arithmeticInLiteralsEnabled ->
97789780 Expr.Const ( Const.Char ( x1 + x2), m, ty)
97799781 | _ ->
9780- EvalArithBinOp ( Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+)) v1 v2
9781- | SpecificBinopExpr g g.unchecked_ subtraction_ vref ( arg1, arg2) ->
9782+ if arithmeticInLiteralsEnabled then
9783+ EvalArithBinOp ( Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+), Checked.(+)) v1 v2
9784+ else
9785+ errorR ( Error ( FSComp.SR.tastNotAConstantExpression(), x.Range))
9786+ x
9787+ | SpecificBinopExpr g g.unchecked_ subtraction_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97829788 let v1 , v2 = EvalAttribArgExpr g arg1, EvalAttribArgExpr g arg2
97839789 match v1, v2 with
97849790 | Expr.Const ( Const.Char x1, m, ty), Expr.Const ( Const.Char x2, _, _) ->
97859791 Expr.Const ( Const.Char ( x1 - x2), m, ty)
97869792 | _ ->
97879793 EvalArithBinOp ( Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-), Checked.(-)) v1 v2
9788- | SpecificBinopExpr g g.unchecked_ multiply_ vref ( arg1, arg2) ->
9794+ | SpecificBinopExpr g g.unchecked_ multiply_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97899795 EvalArithBinOp ( Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*), Checked.(*)) ( EvalAttribArgExpr g arg1) ( EvalAttribArgExpr g arg2)
9790- | SpecificBinopExpr g g.unchecked_ division_ vref ( arg1, arg2) ->
9796+ | SpecificBinopExpr g g.unchecked_ division_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97919797 EvalArithBinOp ((/), (/), (/), (/), (/), (/), (/), (/), (/), (/)) ( EvalAttribArgExpr g arg1) ( EvalAttribArgExpr g arg2)
9792- | SpecificBinopExpr g g.unchecked_ modulus_ vref ( arg1, arg2) ->
9798+ | SpecificBinopExpr g g.unchecked_ modulus_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97939799 EvalArithBinOp ((%), (%), (%), (%), (%), (%), (%), (%), (%), (%)) ( EvalAttribArgExpr g arg1) ( EvalAttribArgExpr g arg2)
9794- | SpecificBinopExpr g g.bitwise_ shift_ left_ vref ( arg1, arg2) ->
9800+ | SpecificBinopExpr g g.bitwise_ shift_ left_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97959801 EvalArithShiftOp ((<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<), (<<<)) ( EvalAttribArgExpr g arg1) ( EvalAttribArgExpr g arg2)
9796- | SpecificBinopExpr g g.bitwise_ shift_ right_ vref ( arg1, arg2) ->
9802+ | SpecificBinopExpr g g.bitwise_ shift_ right_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97979803 EvalArithShiftOp ((>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>), (>>>)) ( EvalAttribArgExpr g arg1) ( EvalAttribArgExpr g arg2)
9798- | SpecificBinopExpr g g.bitwise_ and_ vref ( arg1, arg2) ->
9804+ | SpecificBinopExpr g g.bitwise_ and_ vref ( arg1, arg2) when arithmeticInLiteralsEnabled ->
97999805 let v1 = EvalAttribArgExpr g arg1
98009806
98019807 match v1 with
@@ -9804,7 +9810,7 @@ let rec EvalAttribArgExpr g x =
98049810 | _ ->
98059811 errorR ( Error ( FSComp.SR.tastNotAConstantExpression(), x.Range))
98069812 x
9807- | SpecificUnopExpr g g.unchecked_ unary_ minus_ vref arg1 ->
9813+ | SpecificUnopExpr g g.unchecked_ unary_ minus_ vref arg1 when arithmeticInLiteralsEnabled ->
98089814 let v1 = EvalAttribArgExpr g arg1
98099815
98109816 match v1 with
@@ -9813,17 +9819,17 @@ let rec EvalAttribArgExpr g x =
98139819 | _ ->
98149820 errorR ( Error ( FSComp.SR.tastNotAConstantExpression(), v1.Range))
98159821 x
9816- | SpecificUnopExpr g g.unchecked_ unary_ plus_ vref arg1 ->
9822+ | SpecificUnopExpr g g.unchecked_ unary_ plus_ vref arg1 when arithmeticInLiteralsEnabled ->
98179823 EvalArithUnOp ((~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+), (~+)) ( EvalAttribArgExpr g arg1)
9818- | SpecificUnopExpr g g.unchecked_ unary_ not_ vref arg1 ->
9824+ | SpecificUnopExpr g g.unchecked_ unary_ not_ vref arg1 when arithmeticInLiteralsEnabled ->
98199825 match EvalAttribArgExpr g arg1 with
98209826 | Expr.Const ( Const.Bool value, m, ty) ->
98219827 Expr.Const ( Const.Bool ( not value), m, ty)
98229828 | expr ->
98239829 errorR ( Error ( FSComp.SR.tastNotAConstantExpression(), expr.Range))
98249830 x
98259831 // Detect logical operations on booleans, which are represented as a match expression
9826- | Expr.Match ( decision = TDSwitch ( input = input; cases = [ TCase ( DecisionTreeTest.Const ( Const.Bool test), TDSuccess ([], targetNum)) ]); targets = [| TTarget (_, t0, _); TTarget (_, t1, _) |]) ->
9832+ | Expr.Match ( decision = TDSwitch ( input = input; cases = [ TCase ( DecisionTreeTest.Const ( Const.Bool test), TDSuccess ([], targetNum)) ]); targets = [| TTarget (_, t0, _); TTarget (_, t1, _) |]) when arithmeticInLiteralsEnabled ->
98279833 match EvalAttribArgExpr g ( stripDebugPoints input) with
98289834 | Expr.Const ( Const.Bool value, _, _) ->
98299835 let pass , fail =
0 commit comments