From 0a13ac6f62a3ffb74ac71999b3421f884b36af76 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 11:18:33 +0200 Subject: [PATCH 01/12] initial commit --- src/Compiler/Checking/CheckExpressions.fs | 30 +++++++++---------- src/Compiler/Service/ServiceParsedInputOps.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/SyntaxTree/SyntaxTrivia.fs | 7 +++++ src/Compiler/SyntaxTree/SyntaxTrivia.fsi | 6 ++++ src/Compiler/pars.fsy | 15 ++++++++-- .../data/SyntaxTree/Measure/Constant - 01.fs | 1 + .../SyntaxTree/Measure/Constant - 01.fs.bsl | 17 +++++++++++ .../data/SyntaxTree/Measure/Constant - 02.fs | 1 + .../SyntaxTree/Measure/Constant - 02.fs.bsl | 18 +++++++++++ 11 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 01.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 02.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 92c93b5a623..cd20f7c3f2d 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -787,10 +787,10 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst = let unifyMeasureArg iszero tcr = let measureTy = match synConst with - | SynConst.Measure(_, _, SynMeasure.Anon _) -> + | SynConst.Measure(synMeasure = SynMeasure.Anon _) -> (mkAppTy tcr [TType_measure (Measure.Var (NewAnonTypar (TyparKind.Measure, m, TyparRigidity.Anon, (if iszero then TyparStaticReq.None else TyparStaticReq.HeadType), TyparDynamicReq.No)))]) - | SynConst.Measure(_, _, ms) -> mkAppTy tcr [TType_measure (tcMeasure ms)] + | SynConst.Measure(synMeasure = ms) -> mkAppTy tcr [TType_measure (tcMeasure ms)] | _ -> mkAppTy tcr [TType_measure Measure.One] unif measureTy @@ -843,43 +843,43 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst = | SynConst.UIntPtr i -> unif g.unativeint_ty Const.UIntPtr i - | SynConst.Measure(SynConst.Single f, _, _) -> + | SynConst.Measure(constant = SynConst.Single f) -> unifyMeasureArg (f=0.0f) g.pfloat32_tcr Const.Single f - | SynConst.Measure(SynConst.Double f, _, _) -> + | SynConst.Measure(constant = SynConst.Double f) -> unifyMeasureArg (f=0.0) g.pfloat_tcr Const.Double f - | SynConst.Measure(SynConst.Decimal f, _, _) -> + | SynConst.Measure(constant = SynConst.Decimal f) -> unifyMeasureArg false g.pdecimal_tcr Const.Decimal f - | SynConst.Measure(SynConst.SByte i, _, _) -> + | SynConst.Measure(constant = SynConst.SByte i)-> unifyMeasureArg (i=0y) g.pint8_tcr Const.SByte i - | SynConst.Measure(SynConst.Int16 i, _, _) -> + | SynConst.Measure(constant = SynConst.Int16 i) -> unifyMeasureArg (i=0s) g.pint16_tcr Const.Int16 i - | SynConst.Measure(SynConst.Int32 i, _, _) -> + | SynConst.Measure(constant = SynConst.Int32 i) -> unifyMeasureArg (i=0) g.pint_tcr Const.Int32 i - | SynConst.Measure(SynConst.Int64 i, _, _) -> + | SynConst.Measure(constant = SynConst.Int64 i) -> unifyMeasureArg (i=0L) g.pint64_tcr Const.Int64 i - | SynConst.Measure(SynConst.IntPtr i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.IntPtr i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0L) g.pnativeint_tcr Const.IntPtr i - | SynConst.Measure(SynConst.Byte i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.Byte i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0uy) g.puint8_tcr Const.Byte i - | SynConst.Measure(SynConst.UInt16 i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.UInt16 i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0us) g.puint16_tcr Const.UInt16 i - | SynConst.Measure(SynConst.UInt32 i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.UInt32 i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0u) g.puint_tcr Const.UInt32 i - | SynConst.Measure(SynConst.UInt64 i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.UInt64 i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0UL) g.puint64_tcr Const.UInt64 i - | SynConst.Measure(SynConst.UIntPtr i, _, _) when expandedMeasurablesEnabled -> + | SynConst.Measure(constant = SynConst.UIntPtr i) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0UL) g.punativeint_tcr Const.UIntPtr i | SynConst.Char c -> diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index a0f8a810ccb..d995ced6643 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1832,7 +1832,7 @@ module ParsedInput = List.iter walkType ts walkMemberSig sign walkExpr e - | SynExpr.Const (SynConst.Measure (_, _, m), _) -> walkMeasure m + | SynExpr.Const(constant = SynConst.Measure (synMeasure = m)) -> walkMeasure m | _ -> () and walkMeasure measure = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 2dd3dc51291..b0e7c570fa9 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -158,7 +158,7 @@ type SynConst = | UInt16s of uint16[] - | Measure of constant: SynConst * constantRange: range * SynMeasure + | Measure of constant: SynConst * constantRange: range * synMeasure: SynMeasure * trivia: SynMeasureConstantTrivia | SourceIdentifier of constant: string * value: string * range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index d7f01cd4889..44b4da13008 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -170,7 +170,7 @@ type SynConst = | UInt16s of uint16[] /// Old comment: "we never iterate, so the const here is not another SynConst.Measure" - | Measure of constant: SynConst * constantRange: range * SynMeasure + | Measure of constant: SynConst * constantRange: range * synMeasure: SynMeasure * trivia: SynMeasureConstantTrivia /// Source Line, File, and Path Identifiers /// Containing both the original value as the evaluated value. diff --git a/src/Compiler/SyntaxTree/SyntaxTrivia.fs b/src/Compiler/SyntaxTree/SyntaxTrivia.fs index 497c666f1d6..512a65267b9 100644 --- a/src/Compiler/SyntaxTree/SyntaxTrivia.fs +++ b/src/Compiler/SyntaxTree/SyntaxTrivia.fs @@ -388,3 +388,10 @@ type SynMemberSigMemberTrivia = } static member Zero: SynMemberSigMemberTrivia = { GetSetKeywords = None } + +[] +type SynMeasureConstantTrivia = + { + LessRange: range + GreaterRange: range + } diff --git a/src/Compiler/SyntaxTree/SyntaxTrivia.fsi b/src/Compiler/SyntaxTree/SyntaxTrivia.fsi index fc28dc889b9..1c1007fcafa 100644 --- a/src/Compiler/SyntaxTree/SyntaxTrivia.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTrivia.fsi @@ -507,3 +507,9 @@ type SynMemberSigMemberTrivia = } static member Zero: SynMemberSigMemberTrivia + +/// Represents additional information for SynConst.Measure +[] +type SynMeasureConstantTrivia = + { LessRange: range + GreaterRange: range } diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 26414673888..86ed05ba0eb 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3316,7 +3316,10 @@ constant: { $1, rhs parseState 1 } | rawConstant HIGH_PRECEDENCE_TYAPP measureTypeArg - { SynConst.Measure($1, rhs parseState 1, $3), lhs parseState } + { let synMeasure, trivia = $3 + let mConstant = rhs parseState 1 + let m = unionRanges mConstant trivia.GreaterRange + SynConst.Measure($1, rhs parseState 1, synMeasure, trivia), m } bindingPattern: | headBindingPattern @@ -6193,10 +6196,16 @@ dummyTypeArg: measureTypeArg: | LESS measureTypeExpr GREATER - { $2 } + { let mLess = rhs parseState 1 + let mGreater = rhs parseState 3 + let trivia = { LessRange = mLess; GreaterRange = mGreater } + $2, trivia } | LESS UNDERSCORE GREATER - { SynMeasure.Anon(lhs parseState) } + { let mLess = rhs parseState 1 + let mGreater = rhs parseState 3 + let trivia = { LessRange = mLess; GreaterRange = mGreater } + SynMeasure.Anon(rhs parseState 2), trivia } measureTypeAtom: | path diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs new file mode 100644 index 00000000000..c06d84210d4 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs @@ -0,0 +1 @@ +23<_> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl new file mode 100644 index 00000000000..cf1780d3db9 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl @@ -0,0 +1,17 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 01.fs", false, QualifiedNameOfFile Constant - 01, + [], [], + [SynModuleOrNamespace + ([Constant - 01], false, AnonModule, + [Expr + (Const + (Measure + (Int32 23, (1,0--1,2), Anon (1,3--1,4), + { LessRange = (1,2--1,3) + GreaterRange = (1,4--1,5) }), (1,0--1,5)), (1,0--1,5))], + PreXmlDocEmpty, [], None, (1,0--1,5), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,5) parse warning The declarations in this file will be placed in an implicit module 'Constant - 01' based on the file name 'Constant - 01.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs new file mode 100644 index 00000000000..353e9af83ae --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs @@ -0,0 +1 @@ +23< cm > diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl new file mode 100644 index 00000000000..42949221ba5 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl @@ -0,0 +1,18 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 02.fs", false, QualifiedNameOfFile Constant - 02, + [], [], + [SynModuleOrNamespace + ([Constant - 02], false, AnonModule, + [Expr + (Const + (Measure + (Int32 23, (1,0--1,2), + Seq ([Named ([cm], (1,5--1,7))], (1,5--1,7)), + { LessRange = (1,2--1,3) + GreaterRange = (1,9--1,10) }), (1,0--1,10)), (1,0--1,10))], + PreXmlDocEmpty, [], None, (1,0--1,10), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,10) parse warning The declarations in this file will be placed in an implicit module 'Constant - 02' based on the file name 'Constant - 02.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. From c9a7ad6f22e2aacb81f95bcb4c579ec15f1f8e5f Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 12:04:35 +0200 Subject: [PATCH 02/12] adjust existing baseline files --- ...easureContainsTheRangeOfTheConstant.fs.bsl | 30 +++++++++++-------- .../SynMeasureParenHasCorrectRange.fs.bsl | 11 +++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/service/data/SyntaxTree/Measure/MeasureContainsTheRangeOfTheConstant.fs.bsl b/tests/service/data/SyntaxTree/Measure/MeasureContainsTheRangeOfTheConstant.fs.bsl index f6876cb2bfb..b0150fbdc0b 100644 --- a/tests/service/data/SyntaxTree/Measure/MeasureContainsTheRangeOfTheConstant.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/MeasureContainsTheRangeOfTheConstant.fs.bsl @@ -15,11 +15,13 @@ ImplFile Const (Measure (Decimal 1.0M, (2,8--2,12), - Seq ([Named ([cm], (2,13--2,15))], (2,13--2,15))), - (2,8--2,16)), (2,4--2,5), Yes (2,0--2,16), - { LeadingKeyword = Let (2,0--2,3) - InlineKeyword = None - EqualsRange = Some (2,6--2,7) })], (2,0--2,16)); + Seq ([Named ([cm], (2,13--2,15))], (2,13--2,15)), + { LessRange = (2,12--2,13) + GreaterRange = (2,15--2,16) }), (2,8--2,16)), + (2,4--2,5), Yes (2,0--2,16), { LeadingKeyword = Let (2,0--2,3) + InlineKeyword = None + EqualsRange = Some (2,6--2,7) })], + (2,0--2,16)); Let (false, [SynBinding @@ -31,11 +33,13 @@ ImplFile Const (Measure (Double 7.0, (3,8--3,13), - Seq ([Named ([cm], (3,14--3,16))], (3,14--3,16))), - (3,8--3,17)), (3,4--3,5), Yes (3,0--3,17), - { LeadingKeyword = Let (3,0--3,3) - InlineKeyword = None - EqualsRange = Some (3,6--3,7) })], (3,0--3,17))], - PreXmlDocEmpty, [], None, (2,0--4,0), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) + Seq ([Named ([cm], (3,14--3,16))], (3,14--3,16)), + { LessRange = (3,13--3,14) + GreaterRange = (3,16--3,17) }), (3,8--3,17)), + (3,4--3,5), Yes (3,0--3,17), { LeadingKeyword = Let (3,0--3,3) + InlineKeyword = None + EqualsRange = Some (3,6--3,7) })], + (3,0--3,17))], PreXmlDocEmpty, [], None, (2,0--4,0), + { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl b/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl index dee406a9a08..71daea6c875 100644 --- a/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl @@ -15,8 +15,9 @@ ImplFile (Seq ([Named ([staff], (2,10--2,15)); Named ([weeks], (2,16--2,21))], (2,10--2,21)), - (2,9--2,22))], (2,9--2,22)), (2,4--2,22))), - (2,0--2,23)), (2,0--2,23))], PreXmlDocEmpty, [], None, - (2,0--2,23), { LeadingKeyword = None })], (true, true), - { ConditionalDirectives = [] - CodeComments = [] }, set [])) + (2,9--2,22))], (2,9--2,22)), (2,4--2,22)), + { LessRange = (2,3--2,4) + GreaterRange = (2,22--2,23) }), (2,0--2,23)), (2,0--2,23))], + PreXmlDocEmpty, [], None, (2,0--2,23), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) From 5a95b9ddc30650236bd5a01fb9c098cf6f1f17ef Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 13:08:42 +0200 Subject: [PATCH 03/12] update service surface area baselines --- ...r.Service.SurfaceArea.netstandard20.debug.bsl | 16 ++++++++++++---- ...Service.SurfaceArea.netstandard20.release.bsl | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) 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 be1414fc12f..041e48d4fc4 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 @@ -2080,8 +2080,8 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp. FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position) -FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeAnnotationGivenAtPosition(FSharp.Compiler.Text.Position) +FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean ParseHadErrors FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean get_ParseHadErrors() FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: FSharp.Compiler.Diagnostics.FSharpDiagnostic[] Diagnostics @@ -6004,8 +6004,10 @@ FSharp.Compiler.Syntax.SynConst+IntPtr: Int64 Item FSharp.Compiler.Syntax.SynConst+IntPtr: Int64 get_Item() FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynConst constant FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynConst get_constant() -FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure Item3 -FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure get_Item3() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure get_synMeasure() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure synMeasure +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia get_trivia() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia trivia FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Text.Range constantRange FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Text.Range get_constantRange() FSharp.Compiler.Syntax.SynConst+SByte: SByte Item @@ -6114,7 +6116,7 @@ FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt16(Int16) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt32(Int32) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt64(Int64) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewIntPtr(Int64) -FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewMeasure(FSharp.Compiler.Syntax.SynConst, FSharp.Compiler.Text.Range, FSharp.Compiler.Syntax.SynMeasure) +FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewMeasure(FSharp.Compiler.Syntax.SynConst, FSharp.Compiler.Text.Range, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSByte(SByte) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSingle(Single) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSourceIdentifier(System.String, System.String, FSharp.Compiler.Text.Range) @@ -9695,6 +9697,12 @@ FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Microsoft.FSharp.Core.FSharpO FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] get_BarRange() FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: System.String ToString() FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Void .ctor(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range]) +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range GreaterRange +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range LessRange +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range get_GreaterRange() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range get_LessRange() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: System.String ToString() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: Void .ctor(FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia Zero FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia get_Zero() FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.SyntaxTrivia.GetSetKeywords] GetSetKeywords 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 f4b2e93a5f4..1920db26dbf 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 @@ -2080,8 +2080,8 @@ FSharp.Compiler.CodeAnalysis.FSharpChecker: Void InvalidateConfiguration(FSharp. FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsBindingALambdaAtPosition(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPosContainedInApplication(FSharp.Compiler.Text.Position) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsPositionContainedInACurriedParameter(FSharp.Compiler.Text.Position) -FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeAnnotationGivenAtPosition(FSharp.Compiler.Text.Position) +FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean IsTypeName(FSharp.Compiler.Text.Range) FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean ParseHadErrors FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: Boolean get_ParseHadErrors() FSharp.Compiler.CodeAnalysis.FSharpParseFileResults: FSharp.Compiler.Diagnostics.FSharpDiagnostic[] Diagnostics @@ -6004,8 +6004,10 @@ FSharp.Compiler.Syntax.SynConst+IntPtr: Int64 Item FSharp.Compiler.Syntax.SynConst+IntPtr: Int64 get_Item() FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynConst constant FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynConst get_constant() -FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure Item3 -FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure get_Item3() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure get_synMeasure() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Syntax.SynMeasure synMeasure +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia get_trivia() +FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia trivia FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Text.Range constantRange FSharp.Compiler.Syntax.SynConst+Measure: FSharp.Compiler.Text.Range get_constantRange() FSharp.Compiler.Syntax.SynConst+SByte: SByte Item @@ -6114,7 +6116,7 @@ FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt16(Int16) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt32(Int32) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewInt64(Int64) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewIntPtr(Int64) -FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewMeasure(FSharp.Compiler.Syntax.SynConst, FSharp.Compiler.Text.Range, FSharp.Compiler.Syntax.SynMeasure) +FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewMeasure(FSharp.Compiler.Syntax.SynConst, FSharp.Compiler.Text.Range, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSByte(SByte) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSingle(Single) FSharp.Compiler.Syntax.SynConst: FSharp.Compiler.Syntax.SynConst NewSourceIdentifier(System.String, System.String, FSharp.Compiler.Text.Range) @@ -9695,6 +9697,12 @@ FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Microsoft.FSharp.Core.FSharpO FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range] get_BarRange() FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: System.String ToString() FSharp.Compiler.SyntaxTrivia.SynMatchClauseTrivia: Void .ctor(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Text.Range]) +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range GreaterRange +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range LessRange +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range get_GreaterRange() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: FSharp.Compiler.Text.Range get_LessRange() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: System.String ToString() +FSharp.Compiler.SyntaxTrivia.SynMeasureConstantTrivia: Void .ctor(FSharp.Compiler.Text.Range, FSharp.Compiler.Text.Range) FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia Zero FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia get_Zero() FSharp.Compiler.SyntaxTrivia.SynMemberDefnAbstractSlotTrivia: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.SyntaxTrivia.GetSetKeywords] GetSetKeywords From adf126c8c40b2b102e1f58873b3a9cf9fb6d529d Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 14:51:33 +0200 Subject: [PATCH 04/12] - add range to SynMeasure.One - add tests - update baselines --- src/Compiler/Checking/CheckExpressions.fs | 2 +- src/Compiler/Service/ServiceParsedInputOps.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 6 ++++-- ...ervice.SurfaceArea.netstandard20.debug.bsl | 6 ++++-- ...vice.SurfaceArea.netstandard20.release.bsl | 6 ++++-- .../data/SyntaxTree/Measure/Constant - 03.fs | 1 + .../SyntaxTree/Measure/Constant - 03.fs.bsl | 17 +++++++++++++++ .../data/SyntaxTree/Measure/Constant - 04.fs | 1 + .../SyntaxTree/Measure/Constant - 04.fs.bsl | 20 ++++++++++++++++++ .../data/SyntaxTree/Measure/Constant - 05.fs | 1 + .../SyntaxTree/Measure/Constant - 05.fs.bsl | 21 +++++++++++++++++++ 13 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 03.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 04.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 05.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index cd20f7c3f2d..10651f02257 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -762,7 +762,7 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst = let g = cenv.g let rec tcMeasure ms = match ms with - | SynMeasure.One -> Measure.One + | SynMeasure.One _ -> Measure.One | SynMeasure.Named(tc, m) -> let ad = env.eAccessRights let _, tcref = ForceRaise(ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Use OpenQualified env.eNameResEnv ad tc TypeNameResolutionStaticArgsInfo.DefiniteEmpty PermitDirectReferenceToGeneratedType.No) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index d995ced6643..281b31971ec 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1846,7 +1846,7 @@ module ParsedInput = | SynMeasure.Paren (m, _) | SynMeasure.Power (m, _, _) -> walkMeasure m | SynMeasure.Var (ty, _) -> walkTypar ty - | SynMeasure.One + | SynMeasure.One _ | SynMeasure.Anon _ -> () and walkSimplePat spat = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index b0e7c570fa9..ac50c5b08a5 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -182,7 +182,7 @@ type SynMeasure = | Power of measure: SynMeasure * power: SynRationalConst * range: range - | One + | One of range: range | Anon of range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 44b4da13008..9cebf4edbd5 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -199,7 +199,7 @@ type SynMeasure = | Power of measure: SynMeasure * power: SynRationalConst * range: range /// The '1' unit of measure - | One + | One of range: range /// An anonymous (inferred) unit of measure | Anon of range: range diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 86ed05ba0eb..81f20e0d60e 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -6229,7 +6229,8 @@ measureTypePower: | INT32 { if fst $1 <> 1 then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedIntegerLiteralForUnitOfMeasure()) - SynMeasure.One } + let m = rhs parseState 1 + SynMeasure.One(m) } measureTypeSeq: | measureTypePower @@ -6252,7 +6253,8 @@ measureTypeExpr: | INFIX_STAR_DIV_MOD_OP measureTypeExpr { if $1 <> "/" then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) - SynMeasure.Divide(SynMeasure.One, $2, lhs parseState) } + let m = Range.Zero // zero range to signal absence in concrete syntax + SynMeasure.Divide(SynMeasure.One m, $2, lhs parseState) } typar: | QUOTE ident 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 041e48d4fc4..5a1b96920ca 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 @@ -7269,6 +7269,8 @@ FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] get_longId() FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] longId +FSharp.Compiler.Syntax.SynMeasure+One: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynMeasure+One: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Syntax.SynMeasure get_measure() FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Syntax.SynMeasure measure FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Text.Range get_range() @@ -7323,16 +7325,16 @@ FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsVar() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewAnon(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewNamed(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewOne(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewParen(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewPower(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewProduct(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewSeq(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynMeasure], FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewVar(FSharp.Compiler.Syntax.SynTypar, FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure One -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure get_One() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Anon FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Divide FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Named +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+One FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Paren FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Power FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Product 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 1920db26dbf..9981c8dce45 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 @@ -7269,6 +7269,8 @@ FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] get_longId() FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] longId +FSharp.Compiler.Syntax.SynMeasure+One: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynMeasure+One: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Syntax.SynMeasure get_measure() FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Syntax.SynMeasure measure FSharp.Compiler.Syntax.SynMeasure+Paren: FSharp.Compiler.Text.Range get_range() @@ -7323,16 +7325,16 @@ FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsVar() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewAnon(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewNamed(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewOne(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewParen(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewPower(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynRationalConst, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewProduct(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewSeq(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.SynMeasure], FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewVar(FSharp.Compiler.Syntax.SynTypar, FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure One -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure get_One() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Anon FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Divide FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Named +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+One FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Paren FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Power FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure+Product diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs new file mode 100644 index 00000000000..6000bc1531e --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs @@ -0,0 +1 @@ +23<1> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl new file mode 100644 index 00000000000..f1ddd05f292 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl @@ -0,0 +1,17 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 03.fs", false, QualifiedNameOfFile Constant - 03, + [], [], + [SynModuleOrNamespace + ([Constant - 03], false, AnonModule, + [Expr + (Const + (Measure + (Int32 23, (1,0--1,2), Seq ([One (1,3--1,4)], (1,3--1,4)), + { LessRange = (1,2--1,3) + GreaterRange = (1,4--1,5) }), (1,0--1,5)), (1,0--1,5))], + PreXmlDocEmpty, [], None, (1,0--1,5), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,5) parse warning The declarations in this file will be placed in an implicit module 'Constant - 03' based on the file name 'Constant - 03.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs new file mode 100644 index 00000000000..f115d8db405 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs @@ -0,0 +1 @@ +23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl new file mode 100644 index 00000000000..1a85b493086 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl @@ -0,0 +1,20 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 04.fs", false, QualifiedNameOfFile Constant - 04, + [], [], + [SynModuleOrNamespace + ([Constant - 04], false, AnonModule, + [Expr + (Const + (Measure + (Int32 23, (1,0--1,2), + Divide + (One (0,0--0,0), + Seq ([Named ([cm], (1,4--1,6))], (1,4--1,6)), (1,3--1,6)), + { LessRange = (1,2--1,3) + GreaterRange = (1,6--1,7) }), (1,0--1,7)), (1,0--1,7))], + PreXmlDocEmpty, [], None, (1,0--1,7), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,7) parse warning The declarations in this file will be placed in an implicit module 'Constant - 04' based on the file name 'Constant - 04.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs new file mode 100644 index 00000000000..41160e26361 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs @@ -0,0 +1 @@ +42< 0_1 / m> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl new file mode 100644 index 00000000000..65841b70b55 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl @@ -0,0 +1,21 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 05.fs", false, QualifiedNameOfFile Constant - 05, + [], [], + [SynModuleOrNamespace + ([Constant - 05], false, AnonModule, + [Expr + (Const + (Measure + (Int32 42, (1,0--1,2), + Divide + (Seq ([One (1,4--1,7)], (1,4--1,7)), + Seq ([Named ([m], (1,10--1,11))], (1,10--1,11)), + (1,4--1,11)), { LessRange = (1,2--1,3) + GreaterRange = (1,11--1,12) }), + (1,0--1,12)), (1,0--1,12))], PreXmlDocEmpty, [], None, + (1,0--1,12), { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,12) parse warning The declarations in this file will be placed in an implicit module 'Constant - 05' based on the file name 'Constant - 05.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. From 150d2b118f4a84ba45861f6abff674b7bf8536fd Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 16:28:15 +0200 Subject: [PATCH 05/12] make measure1 of SynMeasure.Divide optional --- src/Compiler/Checking/CheckExpressions.fs | 6 ++++-- src/Compiler/Service/ServiceParsedInputOps.fs | 6 ++++-- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 5 ++--- ...ler.Service.SurfaceArea.netstandard20.debug.bsl | 6 +++--- ...r.Service.SurfaceArea.netstandard20.release.bsl | 6 +++--- .../data/SyntaxTree/Measure/Constant - 04.fs.bsl | 14 +++++++------- .../data/SyntaxTree/Measure/Constant - 05.fs.bsl | 2 +- .../Measure/SynMeasureParenHasCorrectRange.fs.bsl | 2 +- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 10651f02257..26604cc1a65 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -774,9 +774,11 @@ let TcConst (cenv: cenv) (overallTy: TType) m env synConst = | SynMeasure.Product(ms1, ms2, _) -> Measure.Prod(tcMeasure ms1, tcMeasure ms2) | SynMeasure.Divide(ms1, (SynMeasure.Seq (_ :: _ :: _, _) as ms2), m) -> warning(Error(FSComp.SR.tcImplicitMeasureFollowingSlash(), m)) - Measure.Prod(tcMeasure ms1, Measure.Inv (tcMeasure ms2)) + let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero) + Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2)) | SynMeasure.Divide(ms1, ms2, _) -> - Measure.Prod(tcMeasure ms1, Measure.Inv (tcMeasure ms2)) + let factor1 = ms1 |> Option.defaultValue (SynMeasure.One Range.Zero) + Measure.Prod(tcMeasure factor1, Measure.Inv (tcMeasure ms2)) | SynMeasure.Seq(mss, _) -> ProdMeasures (List.map tcMeasure mss) | SynMeasure.Anon _ -> error(Error(FSComp.SR.tcUnexpectedMeasureAnon(), m)) | SynMeasure.Var(_, m) -> error(Error(FSComp.SR.tcNonZeroConstantCannotHaveGenericUnit(), m)) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 281b31971ec..f21f1447cd2 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1837,10 +1837,12 @@ module ParsedInput = and walkMeasure measure = match measure with - | SynMeasure.Product (m1, m2, _) - | SynMeasure.Divide (m1, m2, _) -> + | SynMeasure.Product (m1, m2, _) -> walkMeasure m1 walkMeasure m2 + | SynMeasure.Divide (m1, m2, _) -> + m1 |> Option.iter walkMeasure + walkMeasure m2 | SynMeasure.Named (longIdent, _) -> addLongIdent longIdent | SynMeasure.Seq (ms, _) -> List.iter walkMeasure ms | SynMeasure.Paren (m, _) diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index ac50c5b08a5..2243b9f9e0c 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -178,7 +178,7 @@ type SynMeasure = | Seq of measures: SynMeasure list * range: range - | Divide of measure1: SynMeasure * measure2: SynMeasure * range: range + | Divide of measure1: SynMeasure option * measure2: SynMeasure * range: range | Power of measure: SynMeasure * power: SynRationalConst * range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 9cebf4edbd5..93e11b6cc3f 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -193,7 +193,7 @@ type SynMeasure = | Seq of measures: SynMeasure list * range: range /// A division of two units of measure, e.g. 'kg / m' - | Divide of measure1: SynMeasure * measure2: SynMeasure * range: range + | Divide of measure1: SynMeasure option * measure2: SynMeasure * range: range /// A power of a unit of measure, e.g. 'kg ^ 2' | Power of measure: SynMeasure * power: SynRationalConst * range: range diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 81f20e0d60e..bda73073b60 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -6249,12 +6249,11 @@ measureTypeExpr: | measureTypeExpr INFIX_STAR_DIV_MOD_OP measureTypeExpr { if $2 <> "*" && $2 <> "/" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) if $2 = "*" then SynMeasure.Product($1, $3, lhs parseState) - else SynMeasure.Divide($1, $3, lhs parseState) } + else SynMeasure.Divide(Some $1, $3, lhs parseState) } | INFIX_STAR_DIV_MOD_OP measureTypeExpr { if $1 <> "/" then reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) - let m = Range.Zero // zero range to signal absence in concrete syntax - SynMeasure.Divide(SynMeasure.One m, $2, lhs parseState) } + SynMeasure.Divide(None, $2, lhs parseState) } typar: | QUOTE ident 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 5a1b96920ca..c3bda495832 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 @@ -7259,12 +7259,12 @@ FSharp.Compiler.Syntax.SynMatchClause: Microsoft.FSharp.Core.FSharpOption`1[FSha FSharp.Compiler.Syntax.SynMatchClause: System.String ToString() FSharp.Compiler.Syntax.SynMeasure+Anon: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Anon: FSharp.Compiler.Text.Range range -FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure get_measure1() FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure get_measure2() -FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure measure1 FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure measure2 FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Text.Range range +FSharp.Compiler.Syntax.SynMeasure+Divide: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure] get_measure1() +FSharp.Compiler.Syntax.SynMeasure+Divide: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure] measure1 FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] get_longId() @@ -7323,7 +7323,7 @@ FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsProduct() FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsSeq() FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsVar() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewAnon(FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure], FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewNamed(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewOne(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewParen(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) 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 9981c8dce45..8ae0bd2c2ae 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 @@ -7259,12 +7259,12 @@ FSharp.Compiler.Syntax.SynMatchClause: Microsoft.FSharp.Core.FSharpOption`1[FSha FSharp.Compiler.Syntax.SynMatchClause: System.String ToString() FSharp.Compiler.Syntax.SynMeasure+Anon: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Anon: FSharp.Compiler.Text.Range range -FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure get_measure1() FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure get_measure2() -FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure measure1 FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Syntax.SynMeasure measure2 FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Divide: FSharp.Compiler.Text.Range range +FSharp.Compiler.Syntax.SynMeasure+Divide: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure] get_measure1() +FSharp.Compiler.Syntax.SynMeasure+Divide: Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure] measure1 FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range get_range() FSharp.Compiler.Syntax.SynMeasure+Named: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynMeasure+Named: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident] get_longId() @@ -7323,7 +7323,7 @@ FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsProduct() FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsSeq() FSharp.Compiler.Syntax.SynMeasure: Boolean get_IsVar() FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewAnon(FSharp.Compiler.Text.Range) -FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) +FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewDivide(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMeasure], FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewNamed(Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.Syntax.Ident], FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewOne(FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynMeasure: FSharp.Compiler.Syntax.SynMeasure NewParen(FSharp.Compiler.Syntax.SynMeasure, FSharp.Compiler.Text.Range) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl index 1a85b493086..87263ed5fac 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl @@ -9,12 +9,12 @@ ImplFile (Measure (Int32 23, (1,0--1,2), Divide - (One (0,0--0,0), - Seq ([Named ([cm], (1,4--1,6))], (1,4--1,6)), (1,3--1,6)), - { LessRange = (1,2--1,3) - GreaterRange = (1,6--1,7) }), (1,0--1,7)), (1,0--1,7))], - PreXmlDocEmpty, [], None, (1,0--1,7), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) + (None, Seq ([Named ([cm], (1,4--1,6))], (1,4--1,6)), + (1,3--1,6)), { LessRange = (1,2--1,3) + GreaterRange = (1,6--1,7) }), (1,0--1,7)), + (1,0--1,7))], PreXmlDocEmpty, [], None, (1,0--1,7), + { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) (1,0)-(1,7) parse warning The declarations in this file will be placed in an implicit module 'Constant - 04' based on the file name 'Constant - 04.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl index 65841b70b55..efffb64cbbb 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl @@ -9,7 +9,7 @@ ImplFile (Measure (Int32 42, (1,0--1,2), Divide - (Seq ([One (1,4--1,7)], (1,4--1,7)), + (Some (Seq ([One (1,4--1,7)], (1,4--1,7))), Seq ([Named ([m], (1,10--1,11))], (1,10--1,11)), (1,4--1,11)), { LessRange = (1,2--1,3) GreaterRange = (1,11--1,12) }), diff --git a/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl b/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl index 71daea6c875..49a040624a6 100644 --- a/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/SynMeasureParenHasCorrectRange.fs.bsl @@ -9,7 +9,7 @@ ImplFile (Measure (UInt32 40u, (2,0--2,3), Divide - (Seq ([Named ([hr], (2,4--2,6))], (2,4--2,6)), + (Some (Seq ([Named ([hr], (2,4--2,6))], (2,4--2,6))), Seq ([Paren (Seq From 5826da6d28ac7ab28a6223553ba6ee3929a706d9 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 18:58:35 +0200 Subject: [PATCH 06/12] - add range to SynRationalConst.Integer - add test - update surface baselines --- src/Compiler/Checking/CheckExpressions.fs | 2 +- .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 6 +++--- ...ervice.SurfaceArea.netstandard20.debug.bsl | 4 +++- ...vice.SurfaceArea.netstandard20.release.bsl | 4 +++- .../data/SyntaxTree/Measure/Constant - 06.fs | 1 + .../SyntaxTree/Measure/Constant - 06.fs.bsl | 21 +++++++++++++++++++ 9 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 06.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 26604cc1a65..f88cf34033b 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -753,7 +753,7 @@ let ForNewConstructors tcSink (env: TcEnv) mObjTy methodName meths = /// Typecheck rational constant terms in units-of-measure exponents let rec TcSynRationalConst c = match c with - | SynRationalConst.Integer i -> intToRational i + | SynRationalConst.Integer(value = i) -> intToRational i | SynRationalConst.Negate c2 -> NegRational (TcSynRationalConst c2) | SynRationalConst.Rational(p, q, _) -> DivRational (intToRational p) (intToRational q) diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index e0e31850e33..30a2ebb5db1 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -105,7 +105,7 @@ type InterfaceData = | InterfaceData.ObjExpr (StripParenTypes ty, _) -> let rec (|RationalConst|) = function - | SynRationalConst.Integer i -> string i + | SynRationalConst.Integer(value = i) -> string i | SynRationalConst.Rational (numerator, denominator, _) -> sprintf "(%i/%i)" numerator denominator | SynRationalConst.Negate (RationalConst s) -> sprintf "- %s" s diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 2243b9f9e0c..3f7f6a1f2c0 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -193,7 +193,7 @@ type SynMeasure = [] type SynRationalConst = - | Integer of value: int32 + | Integer of value: int32 * range: range | Rational of numerator: int32 * denominator: int32 * range: range diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 93e11b6cc3f..0f78131e4e1 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -214,7 +214,7 @@ type SynMeasure = [] type SynRationalConst = - | Integer of value: int32 + | Integer of value: int32 * range: range | Rational of numerator: int32 * denominator: int32 * range: range diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index bda73073b60..6aa688cb56c 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3292,15 +3292,15 @@ rationalConstant: | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Integer(fst $1) } + SynRationalConst.Integer(fst $1, lhs parseState) } | MINUS INT32 { if snd $2 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Negate(SynRationalConst.Integer(fst $2)) } + SynRationalConst.Negate(SynRationalConst.Integer(fst $2, lhs parseState)) } atomicUnsignedRationalConstant: | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Integer(fst $1) } + SynRationalConst.Integer(fst $1, lhs parseState) } | LPAREN rationalConstant rparen { $2 } 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 c3bda495832..b422387b6ab 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 @@ -8149,6 +8149,8 @@ FSharp.Compiler.Syntax.SynPat: FSharp.Compiler.Text.Range get_Range() FSharp.Compiler.Syntax.SynPat: Int32 Tag FSharp.Compiler.Syntax.SynPat: Int32 get_Tag() FSharp.Compiler.Syntax.SynPat: System.String ToString() +FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item @@ -8168,7 +8170,7 @@ 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_IsRational() -FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32) +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.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, Int32, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer 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 8ae0bd2c2ae..a5076c5c823 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 @@ -8149,6 +8149,8 @@ FSharp.Compiler.Syntax.SynPat: FSharp.Compiler.Text.Range get_Range() FSharp.Compiler.Syntax.SynPat: Int32 Tag FSharp.Compiler.Syntax.SynPat: Int32 get_Tag() FSharp.Compiler.Syntax.SynPat: System.String ToString() +FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range get_range() +FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item @@ -8168,7 +8170,7 @@ 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_IsRational() -FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewInteger(Int32) +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.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, Int32, FSharp.Compiler.Text.Range) FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Integer diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs new file mode 100644 index 00000000000..b320009a057 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs @@ -0,0 +1 @@ +42 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl new file mode 100644 index 00000000000..c8a23733d3d --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl @@ -0,0 +1,21 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 06.fs", false, QualifiedNameOfFile Constant - 06, + [], [], + [SynModuleOrNamespace + ([Constant - 06], false, AnonModule, + [Expr + (Const + (Measure + (Int32 42, (1,0--1,2), + Seq + ([Power + (Named ([m], (1,3--1,4)), Integer (12345, (1,5--1,10)), + (1,3--1,10))], (1,3--1,10)), + { LessRange = (1,2--1,3) + GreaterRange = (1,10--1,11) }), (1,0--1,11)), (1,0--1,11))], + PreXmlDocEmpty, [], None, (1,0--1,11), { LeadingKeyword = None })], + (true, true), { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(1,0)-(1,11) parse warning The declarations in this file will be placed in an implicit module 'Constant - 06' based on the file name 'Constant - 06.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. From 596025f1290bdab8b855712050490198f468af97 Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 19:03:47 +0200 Subject: [PATCH 07/12] format --- src/Compiler/Service/ServiceInterfaceStubGenerator.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 30a2ebb5db1..181757bd7c2 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -105,7 +105,7 @@ type InterfaceData = | InterfaceData.ObjExpr (StripParenTypes ty, _) -> let rec (|RationalConst|) = function - | SynRationalConst.Integer(value = i) -> string i + | SynRationalConst.Integer (value = i) -> string i | SynRationalConst.Rational (numerator, denominator, _) -> sprintf "(%i/%i)" numerator denominator | SynRationalConst.Negate (RationalConst s) -> sprintf "- %s" s From fac93848a4f256e2363b97193423fb2a792fc2bd Mon Sep 17 00:00:00 2001 From: dawe Date: Tue, 18 Jul 2023 19:39:24 +0200 Subject: [PATCH 08/12] - add numeratorRange and denominatorRange to SynRationalConst.Rational - add test and put other tests inside a module - update baselines --- src/Compiler/Checking/CheckExpressions.fs | 2 +- .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 4 ++-- ...ervice.SurfaceArea.netstandard20.debug.bsl | 6 ++++- ...vice.SurfaceArea.netstandard20.release.bsl | 6 ++++- .../data/SyntaxTree/Measure/Constant - 01.fs | 2 ++ .../SyntaxTree/Measure/Constant - 01.fs.bsl | 20 +++++++--------- .../data/SyntaxTree/Measure/Constant - 02.fs | 2 ++ .../SyntaxTree/Measure/Constant - 02.fs.bsl | 22 ++++++++--------- .../data/SyntaxTree/Measure/Constant - 03.fs | 2 ++ .../SyntaxTree/Measure/Constant - 03.fs.bsl | 20 +++++++--------- .../data/SyntaxTree/Measure/Constant - 04.fs | 2 ++ .../SyntaxTree/Measure/Constant - 04.fs.bsl | 20 +++++++--------- .../data/SyntaxTree/Measure/Constant - 05.fs | 2 ++ .../SyntaxTree/Measure/Constant - 05.fs.bsl | 22 ++++++++--------- .../data/SyntaxTree/Measure/Constant - 06.fs | 2 ++ .../SyntaxTree/Measure/Constant - 06.fs.bsl | 24 +++++++++---------- .../data/SyntaxTree/Measure/Constant - 07.fs | 3 +++ .../SyntaxTree/Measure/Constant - 07.fs.bsl | 21 ++++++++++++++++ 21 files changed, 110 insertions(+), 78 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 07.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index f88cf34033b..08c7d5b10b2 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -755,7 +755,7 @@ let rec TcSynRationalConst c = match c with | SynRationalConst.Integer(value = i) -> intToRational i | SynRationalConst.Negate c2 -> NegRational (TcSynRationalConst c2) - | SynRationalConst.Rational(p, q, _) -> DivRational (intToRational p) (intToRational q) + | SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q) /// 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 181757bd7c2..184d245db5b 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -106,7 +106,7 @@ type InterfaceData = let rec (|RationalConst|) = function | SynRationalConst.Integer (value = i) -> string i - | SynRationalConst.Rational (numerator, denominator, _) -> sprintf "(%i/%i)" numerator denominator + | SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator | SynRationalConst.Negate (RationalConst s) -> sprintf "- %s" s let rec (|TypeIdent|_|) = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fs b/src/Compiler/SyntaxTree/SyntaxTree.fs index 3f7f6a1f2c0..036229b0477 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -195,7 +195,7 @@ type SynRationalConst = | Integer of value: int32 * range: range - | Rational of numerator: int32 * denominator: int32 * range: range + | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range | Negate of SynRationalConst diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 0f78131e4e1..6dba3105712 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -216,7 +216,7 @@ type SynRationalConst = | Integer of value: int32 * range: range - | Rational of numerator: int32 * denominator: int32 * range: range + | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range | Negate of SynRationalConst diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 6aa688cb56c..a760fb933fd 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3282,13 +3282,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, fst $3, lhs parseState) } + SynRationalConst.Rational(fst $1, rhs parseState 1, 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, fst $4, lhs parseState)) } + SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, fst $4, rhs parseState 4, lhs parseState)) } | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) 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 b422387b6ab..d1d3e576e8b 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 @@ -8155,7 +8155,11 @@ FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_Item() +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() +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 FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 denominator FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_denominator() @@ -8172,7 +8176,7 @@ FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() 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.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, Int32, 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+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational 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 a5076c5c823..f3b51ad9e29 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 @@ -8155,7 +8155,11 @@ FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_Item() +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range denominatorRange +FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() +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 FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 denominator FSharp.Compiler.Syntax.SynRationalConst+Rational: Int32 get_denominator() @@ -8172,7 +8176,7 @@ FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() 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.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst NewRational(Int32, Int32, 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+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Rational diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs index c06d84210d4..9d2417fbbb5 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs @@ -1 +1,3 @@ +module M + 23<_> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl index cf1780d3db9..a9bc46a831a 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 01.fs.bsl @@ -1,17 +1,15 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 01.fs", false, QualifiedNameOfFile Constant - 01, - [], [], + ("/root/Measure/Constant - 01.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 01], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 23, (1,0--1,2), Anon (1,3--1,4), - { LessRange = (1,2--1,3) - GreaterRange = (1,4--1,5) }), (1,0--1,5)), (1,0--1,5))], - PreXmlDocEmpty, [], None, (1,0--1,5), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) - -(1,0)-(1,5) parse warning The declarations in this file will be placed in an implicit module 'Constant - 01' based on the file name 'Constant - 01.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. + (Int32 23, (3,0--3,2), Anon (3,3--3,4), + { LessRange = (3,2--3,3) + GreaterRange = (3,4--3,5) }), (3,0--3,5)), (3,0--3,5))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs index 353e9af83ae..6227d4f5e8e 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs @@ -1 +1,3 @@ +module M + 23< cm > diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl index 42949221ba5..9cc97f47504 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 02.fs.bsl @@ -1,18 +1,16 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 02.fs", false, QualifiedNameOfFile Constant - 02, - [], [], + ("/root/Measure/Constant - 02.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 02], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 23, (1,0--1,2), - Seq ([Named ([cm], (1,5--1,7))], (1,5--1,7)), - { LessRange = (1,2--1,3) - GreaterRange = (1,9--1,10) }), (1,0--1,10)), (1,0--1,10))], - PreXmlDocEmpty, [], None, (1,0--1,10), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) - -(1,0)-(1,10) parse warning The declarations in this file will be placed in an implicit module 'Constant - 02' based on the file name 'Constant - 02.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. + (Int32 23, (3,0--3,2), + Seq ([Named ([cm], (3,5--3,7))], (3,5--3,7)), + { LessRange = (3,2--3,3) + GreaterRange = (3,9--3,10) }), (3,0--3,10)), (3,0--3,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs index 6000bc1531e..592ae699732 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs @@ -1 +1,3 @@ +module M + 23<1> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl index f1ddd05f292..a28e62906de 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 03.fs.bsl @@ -1,17 +1,15 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 03.fs", false, QualifiedNameOfFile Constant - 03, - [], [], + ("/root/Measure/Constant - 03.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 03], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 23, (1,0--1,2), Seq ([One (1,3--1,4)], (1,3--1,4)), - { LessRange = (1,2--1,3) - GreaterRange = (1,4--1,5) }), (1,0--1,5)), (1,0--1,5))], - PreXmlDocEmpty, [], None, (1,0--1,5), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) - -(1,0)-(1,5) parse warning The declarations in this file will be placed in an implicit module 'Constant - 03' based on the file name 'Constant - 03.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. + (Int32 23, (3,0--3,2), Seq ([One (3,3--3,4)], (3,3--3,4)), + { LessRange = (3,2--3,3) + GreaterRange = (3,4--3,5) }), (3,0--3,5)), (3,0--3,5))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs index f115d8db405..dc986dc534a 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs @@ -1 +1,3 @@ +module M + 23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl index 87263ed5fac..5e71c013ca3 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 04.fs.bsl @@ -1,20 +1,18 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 04.fs", false, QualifiedNameOfFile Constant - 04, - [], [], + ("/root/Measure/Constant - 04.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 04], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 23, (1,0--1,2), + (Int32 23, (3,0--3,2), Divide - (None, Seq ([Named ([cm], (1,4--1,6))], (1,4--1,6)), - (1,3--1,6)), { LessRange = (1,2--1,3) - GreaterRange = (1,6--1,7) }), (1,0--1,7)), - (1,0--1,7))], PreXmlDocEmpty, [], None, (1,0--1,7), - { LeadingKeyword = None })], (true, true), + (None, Seq ([Named ([cm], (3,4--3,6))], (3,4--3,6)), + (3,3--3,6)), { LessRange = (3,2--3,3) + GreaterRange = (3,6--3,7) }), (3,0--3,7)), + (3,0--3,7))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,7), { LeadingKeyword = Module (1,0--1,6) })], (true, true), { ConditionalDirectives = [] CodeComments = [] }, set [])) - -(1,0)-(1,7) parse warning The declarations in this file will be placed in an implicit module 'Constant - 04' based on the file name 'Constant - 04.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs index 41160e26361..8c42f71cc48 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs @@ -1 +1,3 @@ +module M + 42< 0_1 / m> diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl index efffb64cbbb..0ebc88c7f0f 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 05.fs.bsl @@ -1,21 +1,19 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 05.fs", false, QualifiedNameOfFile Constant - 05, - [], [], + ("/root/Measure/Constant - 05.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 05], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 42, (1,0--1,2), + (Int32 42, (3,0--3,2), Divide - (Some (Seq ([One (1,4--1,7)], (1,4--1,7))), - Seq ([Named ([m], (1,10--1,11))], (1,10--1,11)), - (1,4--1,11)), { LessRange = (1,2--1,3) - GreaterRange = (1,11--1,12) }), - (1,0--1,12)), (1,0--1,12))], PreXmlDocEmpty, [], None, - (1,0--1,12), { LeadingKeyword = None })], (true, true), + (Some (Seq ([One (3,4--3,7)], (3,4--3,7))), + Seq ([Named ([m], (3,10--3,11))], (3,10--3,11)), + (3,4--3,11)), { LessRange = (3,2--3,3) + GreaterRange = (3,11--3,12) }), + (3,0--3,12)), (3,0--3,12))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,12), { LeadingKeyword = Module (1,0--1,6) })], (true, true), { ConditionalDirectives = [] CodeComments = [] }, set [])) - -(1,0)-(1,12) parse warning The declarations in this file will be placed in an implicit module 'Constant - 05' based on the file name 'Constant - 05.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs index b320009a057..e6ee14a6ef8 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs +++ b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs @@ -1 +1,3 @@ +module M + 42 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl index c8a23733d3d..6496ee9f21a 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 06.fs.bsl @@ -1,21 +1,19 @@ ImplFile (ParsedImplFileInput - ("/root/Measure/Constant - 06.fs", false, QualifiedNameOfFile Constant - 06, - [], [], + ("/root/Measure/Constant - 06.fs", false, QualifiedNameOfFile M, [], [], [SynModuleOrNamespace - ([Constant - 06], false, AnonModule, + ([M], false, NamedModule, [Expr (Const (Measure - (Int32 42, (1,0--1,2), + (Int32 42, (3,0--3,2), Seq ([Power - (Named ([m], (1,3--1,4)), Integer (12345, (1,5--1,10)), - (1,3--1,10))], (1,3--1,10)), - { LessRange = (1,2--1,3) - GreaterRange = (1,10--1,11) }), (1,0--1,11)), (1,0--1,11))], - PreXmlDocEmpty, [], None, (1,0--1,11), { LeadingKeyword = None })], - (true, true), { ConditionalDirectives = [] - CodeComments = [] }, set [])) - -(1,0)-(1,11) parse warning The declarations in this file will be placed in an implicit module 'Constant - 06' based on the file name 'Constant - 06.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file. + (Named ([m], (3,3--3,4)), Integer (12345, (3,5--3,10)), + (3,3--3,10))], (3,3--3,10)), + { LessRange = (3,2--3,3) + GreaterRange = (3,10--3,11) }), (3,0--3,11)), (3,0--3,11))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 07.fs b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs new file mode 100644 index 00000000000..1c83b91385f --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs @@ -0,0 +1,3 @@ +module M + +23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl new file mode 100644 index 00000000000..ced6613a288 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 07.fs.bsl @@ -0,0 +1,21 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 07.fs", false, QualifiedNameOfFile M, [], [], + [SynModuleOrNamespace + ([M], false, NamedModule, + [Expr + (Const + (Measure + (Int32 23, (3,0--3,2), + Seq + ([Power + (Named ([kg], (3,3--3,5)), + Rational + (-12345, (3,21--3,27), 123, (3,28--3,31), + (3,21--3,31)), (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, + (1,0--3,33), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) From f2b1377dd2fd025ce910cd3434e082dbcd83c40b Mon Sep 17 00:00:00 2001 From: dawe Date: Wed, 19 Jul 2023 16:43:26 +0200 Subject: [PATCH 09/12] - extend SynRationalConst.Negate to also have a range - add test - update baselines --- src/Compiler/Checking/CheckExpressions.fs | 2 +- .../Service/ServiceInterfaceStubGenerator.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fs | 2 +- src/Compiler/SyntaxTree/SyntaxTree.fsi | 2 +- src/Compiler/pars.fsy | 18 ++++++++++----- ...ervice.SurfaceArea.netstandard20.debug.bsl | 8 ++++--- ...vice.SurfaceArea.netstandard20.release.bsl | 8 ++++--- .../data/SyntaxTree/Measure/Constant - 08.fs | 3 +++ .../SyntaxTree/Measure/Constant - 08.fs.bsl | 23 +++++++++++++++++++ 9 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 08.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 08c7d5b10b2..d768c8d4e60 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -754,7 +754,7 @@ let ForNewConstructors tcSink (env: TcEnv) mObjTy methodName meths = let rec TcSynRationalConst c = match c with | SynRationalConst.Integer(value = i) -> intToRational i - | SynRationalConst.Negate c2 -> NegRational (TcSynRationalConst c2) + | SynRationalConst.Negate(rationalConst = c2) -> NegRational (TcSynRationalConst c2) | SynRationalConst.Rational(numerator = p; denominator = q) -> DivRational (intToRational p) (intToRational q) /// Typecheck constant terms in expressions and patterns diff --git a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs index 184d245db5b..d016c348666 100644 --- a/src/Compiler/Service/ServiceInterfaceStubGenerator.fs +++ b/src/Compiler/Service/ServiceInterfaceStubGenerator.fs @@ -107,7 +107,7 @@ type InterfaceData = function | SynRationalConst.Integer (value = i) -> string i | SynRationalConst.Rational (numerator = numerator; denominator = denominator) -> sprintf "(%i/%i)" numerator denominator - | SynRationalConst.Negate (RationalConst s) -> sprintf "- %s" s + | SynRationalConst.Negate (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 036229b0477..1a87d1bab9c 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fs +++ b/src/Compiler/SyntaxTree/SyntaxTree.fs @@ -197,7 +197,7 @@ type SynRationalConst = | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range - | Negate of SynRationalConst + | Negate of rationalConst: SynRationalConst * range: range [] type SynAccess = diff --git a/src/Compiler/SyntaxTree/SyntaxTree.fsi b/src/Compiler/SyntaxTree/SyntaxTree.fsi index 6dba3105712..b9f74dc1ece 100644 --- a/src/Compiler/SyntaxTree/SyntaxTree.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTree.fsi @@ -218,7 +218,7 @@ type SynRationalConst = | Rational of numerator: int32 * numeratorRange: range * denominator: int32 * denominatorRange: range * range: range - | Negate of SynRationalConst + | Negate of rationalConst: SynRationalConst * range: range /// Represents an accessibility modifier in F# syntax [] diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index a760fb933fd..fa4c2ccc00b 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3288,7 +3288,7 @@ rationalConstant: { 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)) } + SynRationalConst.Negate(SynRationalConst.Rational(fst $2, rhs parseState 2, fst $4, rhs parseState 4, lhs parseState), lhs parseState) } | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) @@ -3296,7 +3296,7 @@ rationalConstant: | MINUS INT32 { if snd $2 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Negate(SynRationalConst.Integer(fst $2, lhs parseState)) } + SynRationalConst.Negate(SynRationalConst.Integer(fst $2, lhs parseState), lhs parseState) } atomicUnsignedRationalConstant: | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) @@ -3309,7 +3309,7 @@ atomicRationalConstant: | atomicUnsignedRationalConstant { $1 } | MINUS atomicUnsignedRationalConstant - { SynRationalConst.Negate($2) } + { SynRationalConst.Negate($2, lhs parseState) } constant: | rawConstant @@ -5846,7 +5846,9 @@ appTypeCon: appTypeConPower: | appTypeCon INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedInfixOperator()) - if $2 = "^-" then SynType.MeasurePower($1, SynRationalConst.Negate($3), lhs parseState) + if $2 = "^-" then + let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + SynType.MeasurePower($1, SynRationalConst.Negate($3, m), lhs parseState) else SynType.MeasurePower($1, $3, lhs parseState) } | appTypeCon @@ -6003,7 +6005,9 @@ powerType: | atomTypeOrAnonRecdType INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedInfixOperator()) - if $2 = "^-" then SynType.MeasurePower($1, SynRationalConst.Negate($3), lhs parseState) + if $2 = "^-" then + let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + SynType.MeasurePower($1, SynRationalConst.Negate($3, m), lhs parseState) else SynType.MeasurePower($1, $3, lhs parseState) } @@ -6224,7 +6228,9 @@ measureTypePower: | measureTypeAtom INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) - if $2 = "^-" then SynMeasure.Power($1, SynRationalConst.Negate($3), lhs parseState) + if $2 = "^-" then + let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + SynMeasure.Power($1, SynRationalConst.Negate($3, m), lhs parseState) else SynMeasure.Power($1, $3, lhs parseState) } | INT32 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 d1d3e576e8b..77ad2a72df5 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 @@ -8153,8 +8153,10 @@ FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range get_ FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value -FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item -FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_Item() +FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst() +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+Rational: FSharp.Compiler.Text.Range denominatorRange FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange() @@ -8175,7 +8177,7 @@ FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() 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.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+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate 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 f3b51ad9e29..3f8228275c8 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 @@ -8153,8 +8153,10 @@ FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range get_ FSharp.Compiler.Syntax.SynRationalConst+Integer: FSharp.Compiler.Text.Range range FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 get_value() FSharp.Compiler.Syntax.SynRationalConst+Integer: Int32 value -FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst Item -FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_Item() +FSharp.Compiler.Syntax.SynRationalConst+Negate: FSharp.Compiler.Syntax.SynRationalConst get_rationalConst() +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+Rational: FSharp.Compiler.Text.Range denominatorRange FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_denominatorRange() FSharp.Compiler.Syntax.SynRationalConst+Rational: FSharp.Compiler.Text.Range get_numeratorRange() @@ -8175,7 +8177,7 @@ FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsInteger() FSharp.Compiler.Syntax.SynRationalConst: Boolean get_IsNegate() 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.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+Integer FSharp.Compiler.Syntax.SynRationalConst: FSharp.Compiler.Syntax.SynRationalConst+Negate diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs new file mode 100644 index 00000000000..7e02ecb1436 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs @@ -0,0 +1,3 @@ +module M + +23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl new file mode 100644 index 00000000000..dee1d046962 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl @@ -0,0 +1,23 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 08.fs", false, QualifiedNameOfFile M, [], [], + [SynModuleOrNamespace + ([M], false, NamedModule, + [Expr + (Const + (Measure + (Int32 23, (3,0--3,2), + Seq + ([Power + (Named ([kg], (3,3--3,5)), + Negate + (Rational + (12345, (3,13--3,18), 123, (3,19--3,22), + (3,13--3,22)), (3,7--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 = [] + CodeComments = [] }, set [])) From 3da13f3b373b680df1b08ee342ef290a79016438 Mon Sep 17 00:00:00 2001 From: dawe Date: Wed, 19 Jul 2023 17:48:40 +0200 Subject: [PATCH 10/12] fix range of SynRationalConst.Negate to really include the '-' --- src/Compiler/pars.fsy | 12 +++++++++--- .../data/SyntaxTree/Measure/Constant - 08.fs.bsl | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index c0fd4da78b0..69ffff74646 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -5843,7 +5843,9 @@ appTypeConPower: | appTypeCon INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedInfixOperator()) if $2 = "^-" then - let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + let afterMinus = (rhs parseState 2).EndRange + let beforeMinus = mkRange afterMinus.FileName (mkPos afterMinus.EndLine (afterMinus.EndColumn - 1)) afterMinus.End + let m = unionRanges beforeMinus (rhs parseState 3) // include MINUS in Negate range SynType.MeasurePower($1, SynRationalConst.Negate($3, m), lhs parseState) else SynType.MeasurePower($1, $3, lhs parseState) } @@ -6002,7 +6004,9 @@ powerType: | atomTypeOrAnonRecdType INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedInfixOperator()) if $2 = "^-" then - let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + let afterMinus = (rhs parseState 2).EndRange + let beforeMinus = mkRange afterMinus.FileName (mkPos afterMinus.EndLine (afterMinus.EndColumn - 1)) afterMinus.End + let m = unionRanges beforeMinus (rhs parseState 3) // include MINUS in Negate range SynType.MeasurePower($1, SynRationalConst.Negate($3, m), lhs parseState) else SynType.MeasurePower($1, $3, lhs parseState) } @@ -6225,7 +6229,9 @@ measureTypePower: | measureTypeAtom INFIX_AT_HAT_OP atomicRationalConstant { if $2 <> "^" && $2 <> "^-" then reportParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedOperatorForUnitOfMeasure()) if $2 = "^-" then - let m = unionRanges (rhs parseState 2).EndRange (rhs parseState 3) // include MINUS in Negate range + let afterMinus = (rhs parseState 2).EndRange + let beforeMinus = mkRange afterMinus.FileName (mkPos afterMinus.EndLine (afterMinus.EndColumn - 1)) afterMinus.End + let m = unionRanges beforeMinus (rhs parseState 3) // include MINUS in Negate range SynMeasure.Power($1, SynRationalConst.Negate($3, m), lhs parseState) else SynMeasure.Power($1, $3, lhs parseState) } diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl index dee1d046962..18466941b28 100644 --- a/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl +++ b/tests/service/data/SyntaxTree/Measure/Constant - 08.fs.bsl @@ -13,7 +13,7 @@ ImplFile Negate (Rational (12345, (3,13--3,18), 123, (3,19--3,22), - (3,13--3,22)), (3,7--3,23)), (3,3--3,23))], + (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))], From 07a1e62b5f870b150add99fad8583863bf32cc36 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 20 Jul 2023 12:58:57 +0200 Subject: [PATCH 11/12] add another test for SynRationalConst.Negate range with space between hat and MINUS --- .../data/SyntaxTree/Measure/Constant - 09.fs | 3 +++ .../SyntaxTree/Measure/Constant - 09.fs.bsl | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 09.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 09.fs b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs new file mode 100644 index 00000000000..048a0a46305 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs @@ -0,0 +1,3 @@ +module M + +23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl new file mode 100644 index 00000000000..0cd029ea905 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 09.fs.bsl @@ -0,0 +1,23 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 09.fs", false, QualifiedNameOfFile M, [], [], + [SynModuleOrNamespace + ([M], false, NamedModule, + [Expr + (Const + (Measure + (Int32 23, (3,0--3,2), + Seq + ([Power + (Named ([kg], (3,3--3,5)), + 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))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) From 0f27536e69fe3defd89f2fc06141cc5dc4111c79 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 20 Jul 2023 18:11:50 +0200 Subject: [PATCH 12/12] don't include minus in range of SynRationalConst.Integer in rationalConstant rule --- src/Compiler/pars.fsy | 2 +- .../data/SyntaxTree/Measure/Constant - 10.fs | 3 +++ .../SyntaxTree/Measure/Constant - 10.fs.bsl | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 10.fs create mode 100644 tests/service/data/SyntaxTree/Measure/Constant - 10.fs.bsl diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 69ffff74646..bccf12bdb27 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3292,7 +3292,7 @@ rationalConstant: | MINUS INT32 { if snd $2 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) - SynRationalConst.Negate(SynRationalConst.Integer(fst $2, lhs parseState), lhs parseState) } + SynRationalConst.Negate(SynRationalConst.Integer(fst $2, rhs parseState 2), lhs parseState) } atomicUnsignedRationalConstant: | INT32 { if snd $1 then errorR(Error(FSComp.SR.lexOutsideThirtyTwoBitSigned(), lhs parseState)) diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 10.fs b/tests/service/data/SyntaxTree/Measure/Constant - 10.fs new file mode 100644 index 00000000000..5be24e325f0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 10.fs @@ -0,0 +1,3 @@ +module M + +23 diff --git a/tests/service/data/SyntaxTree/Measure/Constant - 10.fs.bsl b/tests/service/data/SyntaxTree/Measure/Constant - 10.fs.bsl new file mode 100644 index 00000000000..b9c978dc067 --- /dev/null +++ b/tests/service/data/SyntaxTree/Measure/Constant - 10.fs.bsl @@ -0,0 +1,20 @@ +ImplFile + (ParsedImplFileInput + ("/root/Measure/Constant - 10.fs", false, QualifiedNameOfFile M, [], [], + [SynModuleOrNamespace + ([M], false, NamedModule, + [Expr + (Const + (Measure + (Int32 23, (3,0--3,2), + Seq + ([Power + (Named ([kg], (3,3--3,5)), + Negate (Integer (456, (3,7--3,10)), (3,6--3,10)), + (3,3--3,10))], (3,3--3,10)), + { LessRange = (3,2--3,3) + GreaterRange = (3,10--3,11) }), (3,0--3,11)), (3,0--3,11))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set []))