diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 0e7fa94ba39..7bf3e5ee399 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -757,6 +757,7 @@ let rec TcSynRationalConst c = | SynRationalConst.Integer(value = i) -> intToRational i | SynRationalConst.Negate(rationalConst = c2) -> NegRational (TcSynRationalConst c2) | SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q) + | SynRationalConst.Paren(rationalConst = c) -> TcSynRationalConst c /// Typecheck constant terms in expressions and patterns let TcConst (cenv: cenv) (overallTy: TType) m env synConst = diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 4f1c91ca373..cc56ba41494 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -106,8 +106,9 @@ type InterfaceData = let rec (|RationalConst|) = function | SynRationalConst.Integer (value = i) -> string i - | SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator + | SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "%i/%i" numerator denominator | SynRationalConst.Negate (rationalConst = (RationalConst s)) -> sprintf "- %s" s + | SynRationalConst.Paren (rationalConst = (RationalConst s)) -> sprintf "(%s)" s let rec (|TypeIdent|_|) = function diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 0a82bb5dfbb..9ea664863dc 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -195,10 +195,12 @@ type SynRationalConst = | Integer of value: int32 * range: range - | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range + | Rational of numerator: int32 * numeratorRange: range * divRange: range * denominator: int32 * denominatorRange: range * range: range | Negate of rationalConst: SynRationalConst * range: range + | Paren of rationalConst: SynRationalConst * range: range + [] type SynAccess = | Public of range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 1bb11f21d7c..0f1f6e858d6 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -216,10 +216,18 @@ type SynRationalConst = | Integer of value: int32 * range: range - | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range + | Rational of + numerator: int32 * + numeratorRange: range * + divRange: range * + denominator: int32 * + denominatorRange: range * + range: range | Negate of rationalConst: SynRationalConst * range: range + | Paren of rationalConst: SynRationalConst * range: range + /// Represents an accessibility modifier in F# syntax [] type SynAccess = diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 65fe63a6708..a6b398b3979 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3314,13 +3314,13 @@ rationalConstant: { if $2 <> "/" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) if fst $3 = 0 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsIllegalDenominatorForMeasureExponent()) if (snd $1) || (snd $3) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Rational(fst $1, rhs parseState 1, fst $3, rhs parseState 3, lhs parseState) } + SynRationalConst.Rational(fst $1, rhs parseState 1, rhs parseState 2, fst $3, rhs parseState 3, lhs parseState) } | MINUS INT32 INFIX_STAR_DIV_MOD_OP INT32 { if $3 <> "/" then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) if fst $4 = 0 then reportParseErrorAt (rhs parseState 4) (FSComp.SR.parsIllegalDenominatorForMeasureExponent()) if (snd $2) || (snd $4) then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, fst $4, rhs parseState 4, lhs parseState), lhs parseState) } + SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, rhs parseState 3, fst $4, rhs parseState 4, lhs parseState), lhs parseState) } | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) @@ -3335,7 +3335,7 @@ atomicUnsignedRationalConstant: SynRationalConst.Integer(fst $1, lhs parseState) } | LPAREN rationalConstant rparen - { $2 } + { SynRationalConst.Paren($2, rhs2 parseState 1 3) } atomicRationalConstant: | atomicUnsignedRationalConstant { $1 } diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index ae6c5c79079..92ea2574c7a 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst() +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange @@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator() FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate +FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate +FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() +FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational() FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index ae6c5c79079..92ea2574c7a 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -8238,8 +8238,14 @@ FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRation FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst rationalConst FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Text.Range range +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst() +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Syntax.SynRationalConst rationalConst +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynRationalConst+Paren: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range divRange FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_divRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range numeratorRange @@ -8250,18 +8256,23 @@ FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_numerator() FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 numerator FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Integer FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Negate +FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Paren FSharp.Compiler.Syntax.SynRationalConst+Tags: Int32 Rational FSharp.Compiler.Syntax.SynRationalConst: Boolean IsInteger FSharp.Compiler.Syntax.SynRationalConst: Boolean IsNegate +FSharp.Compiler.Syntax.SynRationalConst: Boolean IsParen FSharp.Compiler.Syntax.SynRationalConst: Boolean IsRational FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() +FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsParen() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsRational() FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewNegate(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewParen(FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range, Int32, FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate +FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Paren FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Tags FSharp.Compiler.Syntax.SynRationalConst: Int32 Tag diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl index 1485e64fd8c..db9e83c0fb8 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl @@ -10,9 +10,11 @@ ImplFile Seq ([Power (Named ([kg], (3,3--3,5)), (3,8--3,9), - Rational - (-12345, (3,21--3,27), 123, (3,28--3,31), - (3,21--3,31)), (3,3--3,32))], (3,3--3,32)), + Paren + (Rational + (-12345, (3,21--3,27), (3,27--3,28), 123, + (3,28--3,31), (3,21--3,31)), (3,20--3,32)), + (3,3--3,32))], (3,3--3,32)), { LessRange = (3,2--3,3) GreaterRange = (3,32--3,33) }), (3,0--3,33)), (3,0--3,33))], PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl index cdc20a7bbe4..b4a8f0b48c2 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl @@ -11,12 +11,13 @@ ImplFile ([Power (Named ([kg], (3,3--3,5)), (3,5--3,6), Negate - (Rational - (12345, (3,13--3,18), 123, (3,19--3,22), - (3,13--3,22)), (3,6--3,23)), (3,3--3,23))], - (3,3--3,23)), { LessRange = (3,2--3,3) - GreaterRange = (3,23--3,24) }), - (3,0--3,24)), (3,0--3,24))], + (Paren + (Rational + (12345, (3,13--3,18), (3,18--3,19), 123, + (3,19--3,22), (3,13--3,22)), (3,12--3,23)), + (3,6--3,23)), (3,3--3,23))], (3,3--3,23)), + { LessRange = (3,2--3,3) + GreaterRange = (3,23--3,24) }), (3,0--3,24)), (3,0--3,24))], PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, (1,0--3,24), { LeadingKeyword = Module (1,0--1,6) })], (true, true), { ConditionalDirectives = [] diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl index 83f101df01a..2eeee44a379 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl @@ -11,12 +11,13 @@ ImplFile ([Power (Named ([kg], (3,3--3,5)), (3,5--3,6), Negate - (Rational - (12345, (3,10--3,15), 123, (3,16--3,19), - (3,10--3,19)), (3,7--3,20)), (3,3--3,20))], - (3,3--3,20)), { LessRange = (3,2--3,3) - GreaterRange = (3,20--3,21) }), - (3,0--3,21)), (3,0--3,21))], + (Paren + (Rational + (12345, (3,10--3,15), (3,15--3,16), 123, + (3,16--3,19), (3,10--3,19)), (3,9--3,20)), + (3,7--3,20)), (3,3--3,20))], (3,3--3,20)), + { LessRange = (3,2--3,3) + GreaterRange = (3,20--3,21) }), (3,0--3,21)), (3,0--3,21))], PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, (1,0--3,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), { ConditionalDirectives = []