Skip to content

Commit ff12727

Browse files
committed
Add lang feature flag
1 parent 45e33cb commit ff12727

18 files changed

+100
-16
lines changed

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQua
15581558
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
15591559
featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute on declaring types, modules"
15601560
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
1561+
featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals"
15611562
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
15621563
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
15631564
3354,tcNotAFunctionButIndexerIndexingNotYetEnabled,"This expression supports indexing, e.g. 'expr.[index]'. The syntax 'expr[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type LanguageFeature =
5757
| MatchNotAllowedForUnionCaseWithNoData
5858
| CSharpExtensionAttributeNotRequired
5959
| ErrorForNonVirtualMembersOverrides
60+
| ArithmeticInLiterals
6061

6162
/// LanguageVersion management
6263
type LanguageVersion(versionText) =
@@ -130,6 +131,7 @@ type LanguageVersion(versionText) =
130131
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, previewVersion
131132
LanguageFeature.CSharpExtensionAttributeNotRequired, previewVersion
132133
LanguageFeature.ErrorForNonVirtualMembersOverrides, previewVersion
134+
LanguageFeature.ArithmeticInLiterals, previewVersion
133135

134136
]
135137

@@ -238,8 +240,9 @@ type LanguageVersion(versionText) =
238240
| LanguageFeature.InterfacesWithAbstractStaticMembers -> FSComp.SR.featureInterfacesWithAbstractStaticMembers ()
239241
| LanguageFeature.SelfTypeConstraints -> FSComp.SR.featureSelfTypeConstraints ()
240242
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()
241-
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
242-
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
243+
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
244+
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
245+
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
243246

244247
/// Get a version string associated with the given feature.
245248
static member GetFeatureVersionString feature =

src/Compiler/Facilities/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type LanguageFeature =
4747
| MatchNotAllowedForUnionCaseWithNoData
4848
| CSharpExtensionAttributeNotRequired
4949
| ErrorForNonVirtualMembersOverrides
50+
| ArithmeticInLiterals
5051

5152
/// LanguageVersion management
5253
type LanguageVersion =

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">aplikativní výpočetní výrazy</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">atributy napravo od klíčového slova Module</target>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">applikative Berechnungsausdrücke</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">Attribute rechts vom "Module"-Schlüsselwort</target>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">expresiones de cálculo aplicativas</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">atributos a la derecha de la palabra clave “módulo”</target>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">expressions de calcul applicatives</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">attributs à droite du mot clé 'module'</target>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">espressioni di calcolo applicativo</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">attributi a destra della parola chiave 'module'</target>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<target state="translated">適用できる計算式</target>
143143
<note />
144144
</trans-unit>
145+
<trans-unit id="featureArithmeticInLiterals">
146+
<source>Allow arithmetic and logical operations in literals</source>
147+
<target state="new">Allow arithmetic and logical operations in literals</target>
148+
<note />
149+
</trans-unit>
145150
<trans-unit id="featureAttributesToRightOfModuleKeyword">
146151
<source>attributes to the right of the 'module' keyword</source>
147152
<target state="translated">'module' キーワードの右側の属性</target>

0 commit comments

Comments
 (0)