diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md index b69621fc796..9a25bb09dde 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.100.md @@ -24,6 +24,7 @@ ### Changed * Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645)) +* Allow comma as separator for pattern matching on multiple named discriminated unions fields. ([PR #18833](https://github.com/dotnet/fsharp/pull/18833)) ### Breaking Changes diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index b9afee7582e..dd25655d745 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -11,6 +11,7 @@ * Allow `let!`, `use!`, `and!` type annotations without requiring parentheses (([PR #18508](https://github.com/dotnet/fsharp/pull/18508) and [PR #18682](https://github.com/dotnet/fsharp/pull/18682))) * Exception names are now validated for illegal characters using the same mechanism as types/modules/namespaces ([Issue #18763](https://github.com/dotnet/fsharp/issues/18763)) * Support tail calls in computation expressions ([PR #18804](https://github.com/dotnet/fsharp/pull/18804)) +* Allow comma as separator for pattern matching on multiple named discriminated unions fields. ([PR #18833](https://github.com/dotnet/fsharp/pull/18833)) ### Fixed diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 1f2dc3cfb3c..ba2a19d72c6 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1614,6 +1614,7 @@ featureWarningWhenMultipleRecdTypeChoice,"Raises warnings when multiple record t featureImprovedImpliedArgumentNames,"Improved implied argument names" featureStrictIndentation,"Raises errors on incorrect indentation, allows better recovery and analysis during editing" featureConstraintIntersectionOnFlexibleTypes,"Constraint intersection on flexible types" +featureAllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields,"Allow comma as separator for pattern matching on multiple named discriminated unions fields" featureChkNotTailRecursive,"Raises warnings if a member or function has the 'TailCall' attribute, but is not being used in a tail recursive way." featureWhileBang,"'while!' expression" featureExtendedFixedBindings,"extended fixed bindings for byref and GetPinnableReference" diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 9e57e5b96af..49c58e3ec5a 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -104,6 +104,7 @@ type LanguageFeature = | ScopedNowarn | AllowTypedLetUseAndBang | ReturnFromFinal + | AllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields /// LanguageVersion management type LanguageVersion(versionText) = @@ -243,6 +244,7 @@ type LanguageVersion(versionText) = // F# preview (still preview in 10.0) LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work + LanguageFeature.AllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -412,6 +414,8 @@ type LanguageVersion(versionText) = | LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn () | LanguageFeature.AllowTypedLetUseAndBang -> FSComp.SR.featureAllowLetOrUseBangTypeAnnotationWithoutParens () | LanguageFeature.ReturnFromFinal -> FSComp.SR.featureReturnFromFinal () + | LanguageFeature.AllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields -> + FSComp.SR.featureAllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 2e123eb1593..7c9c0af243d 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -95,6 +95,7 @@ type LanguageFeature = | ScopedNowarn | AllowTypedLetUseAndBang | ReturnFromFinal + | AllowCommaAsSeparatorForPatternMatchingOnMultipleNamedDiscriminatedUnionsFields /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 4b5e3cf9028..d66ee3c21c6 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1479,7 +1479,7 @@ module ParsedInput = | SyntaxNode.SynExpr(SynExpr.Record(None, _, fields, _)) :: _ -> let isFirstField = match field, fields with - | Some contextLid, SynExprRecordField(fieldName = lid, _) :: _ -> contextLid.Range = lid.Range + | Some contextLid, SynExprRecordField(fieldName = (lid, _)) :: _ -> contextLid.Range = lid.Range | _ -> false RecordContext.New(completionPath, isFirstField) diff --git a/src/Compiler/Service/SynExpr.fs b/src/Compiler/Service/SynExpr.fs index 9fd1b3a888a..2711ce85faf 100644 --- a/src/Compiler/Service/SynExpr.fs +++ b/src/Compiler/Service/SynExpr.fs @@ -1112,7 +1112,7 @@ module SynExpr = match recordFields with | [] -> false | SynExprRecordField(expr = Some(SynExpr.Paren(expr = Is inner)); blockSeparator = Some _) :: SynExprRecordField( - fieldName = SynLongIdent(id = id :: _), _) :: _ -> problematic inner.Range id.idRange + fieldName = (SynLongIdent(id = id :: _), _)) :: _ -> problematic inner.Range id.idRange | _ :: recordFields -> loop recordFields loop recordFields diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index a8225213eb6..d57b9b31021 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -3655,13 +3655,16 @@ conjPatternElements: { $3 :: $1 :: [] } namePatPairs: - | namePatPair opt_seps + | namePatPair opt_namePatSep { [$1] } - | namePatPair seps namePatPairs + | namePatPair namePatSep namePatPairs { $1 :: $3 } - | namePatPair seps seps namePatPairs + | namePatPair namePatSep UNDERSCORE + { [$1] } + + | namePatPair namePatSep namePatSep namePatPairs { reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsExpectingPattern ()) ($1 :: $4) } @@ -3700,6 +3703,7 @@ constrPattern: let m = unionRanges (rhs2 parseState 1 2) argsM SynPat.LongIdent(lid, None, Some $2, args, vis, m) } + | atomicPatternLongIdent atomicPatsOrNamePatPairs %prec pat_app { let vis, lid = $1 let args, argsM = $2 @@ -6987,6 +6991,20 @@ seps: | OBLOCKSEP SEMICOLON { Some (rhs parseState 2) } | SEMICOLON OBLOCKSEP { Some (rhs parseState 1) } +/* Unified separator for name pattern pairs that handles both semicolon and comma */ +namePatSep: + | OBLOCKSEP { None } + | SEMICOLON { Some (rhs parseState 1) } + | COMMA { Some (rhs parseState 1) } + | OBLOCKSEP SEMICOLON { Some (rhs parseState 2) } + | OBLOCKSEP COMMA { Some (rhs parseState 2) } + | SEMICOLON OBLOCKSEP { Some (rhs parseState 1) } + | COMMA OBLOCKSEP { Some (rhs parseState 1) } + +opt_namePatSep: + | namePatSep { } + | /* EMPTY */ { } + /* An 'end' that's optional only in #light, where an ODECLEND gets inserted, and explicit 'end's get converted to OEND */ declEnd: | ODECLEND diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 7333400397b..f08720fae06 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index ea6271cfbcb..8edbb31f222 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 6abcce332e0..db224b293f3 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 4eb06dccb14..93528f86cbd 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 4e48e1db287..1e2b92437dd 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 295256c5cf4..2b0d69b3763 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 7ab04d5a12a..ba55f9cd12a 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index b31f4083071..184988d775d 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 3e544e2f90c..0ec640c107e 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 75f9c8dadc7..5b052103fb6 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 66166fd9023..bd2d5873955 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 50981ab1e98..3729b1282a5 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index aa2c95dbd4b..aaa7f3b7b1c 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -287,6 +287,11 @@ Allow access modifiers to auto properties getters and setters + + Allow comma as separator for pattern matching on multiple named discriminated unions fields + Allow comma as separator for pattern matching on multiple named discriminated unions fields + + Allow let! and use! type annotations without requiring parentheses Allow let! and use! type annotations without requiring parentheses diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs.fs new file mode 100644 index 00000000000..a7705686a9d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs.fs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Conformance.PatternMatching + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + +module NamedPatPairs = + [] + let ``Preview: NamedPatPairs - NamedPatPairs01_fs`` compilation = + compilation + |> ignoreWarnings + |> withLangVersionPreview + |> typecheck + |> shouldSucceed + + [] + let ``Version9 NamedPatPairs - NamedPatPairs01_fs`` compilation = + compilation + |> ignoreWarnings + |> withLangVersion90 + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 3350, Line 8, Col 18, Line 8, Col 19, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater."); + (Error 3350, Line 9, Col 18, Line 9, Col 19, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater."); + (Error 3350, Line 9, Col 25, Line 9, Col 26, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater."); + (Error 3350, Line 19, Col 18, Line 19, Col 19, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater."); + (Error 3350, Line 20, Col 18, Line 20, Col 19, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater."); + (Error 3350, Line 21, Col 25, Line 21, Col 26, "Feature 'Allow comma as separator for pattern matching on multiple named discriminated unions fields' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.") + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs01.fs new file mode 100644 index 00000000000..24c02f7cc99 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs01.fs @@ -0,0 +1,21 @@ +// #Conformance #PatternMatching #NamedPatPairs +type MyUnion = + | CaseA of a: int * b: string + | CaseB of x: float * y: bool * z: char + +let testComma value = + match value with + | CaseA(a = x, b = y) -> sprintf "CaseA: a=%d, b=%s" x y + | CaseB(x = p, y = q, z = r) -> sprintf "CaseB: x=%f, y=%b, z=%c" p q r + +let testSemicolon value = + match value with + | CaseA(a = x; b = y) -> sprintf "CaseA: a=%d, b=%s" x y + | CaseB(x = p; y = q; z = r) -> sprintf "CaseB: x=%f, y=%b, z=%c" p q r + +let testMixed value = + match value with + | CaseA(a = x; b = y) -> sprintf "CaseA: a=%d, b=%s" x y + | CaseB(x = p, y = q; z = r) -> sprintf "CaseB: x=%f, y=%b, z=%c" p q r + | CaseA(a = x, b = y) -> sprintf "CaseA: a=%d, b=%s" x y + | CaseB(x = p; y = q, z = r) -> sprintf "CaseB: x=%f, y=%b, z=%c" p q r \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index da13333f878..6ade1f800d6 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -111,6 +111,7 @@ + diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 06.fs b/tests/service/data/SyntaxTree/Pattern/Named field 06.fs new file mode 100644 index 00000000000..58cb8775530 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 06.fs @@ -0,0 +1,4 @@ +module Module + +match 1 with +| A(a = _, b = _) -> 2 diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 06.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 06.fs.bsl new file mode 100644 index 00000000000..39f1cd8229f --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 06.fs.bsl @@ -0,0 +1,25 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 06.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,12), Const (Int32 1, (3,6--3,7)), + [SynMatchClause + (LongIdent + (SynLongIdent ([A], [], [None]), None, None, + NamePatPairs + ([(a, Some (4,6--4,7), Wild (4,8--4,9)); + (b, Some (4,13--4,14), Wild (4,15--4,16))], + (4,4--4,17), { ParenRange = (4,3--4,17) }), None, + (4,2--4,17)), None, Const (Int32 2, (4,21--4,22)), + (4,2--4,22), Yes, { ArrowRange = Some (4,18--4,20) + BarRange = Some (4,0--4,1) })], + (3,0--4,22), { MatchKeyword = (3,0--3,5) + WithKeyword = (3,8--3,12) }), (3,0--4,22))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--4,22), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 07.fs b/tests/service/data/SyntaxTree/Pattern/Named field 07.fs new file mode 100644 index 00000000000..4c5c22e0efd --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 07.fs @@ -0,0 +1,5 @@ +module Module + +match 1 with +| A(a = _, b = ) -> 2 + diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 07.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 07.fs.bsl new file mode 100644 index 00000000000..2ce9cc830e9 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 07.fs.bsl @@ -0,0 +1,28 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 07.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,12), Const (Int32 1, (3,6--3,7)), + [SynMatchClause + (LongIdent + (SynLongIdent ([A], [], [None]), None, None, + NamePatPairs + ([(a, Some (4,6--4,7), Wild (4,8--4,9)); + (b, Some (4,13--4,14), + FromParseError (Wild (4,14--4,14), (4,14--4,14)))], + (4,4--4,16), { ParenRange = (4,3--4,16) }), None, + (4,2--4,16)), None, Const (Int32 2, (4,20--4,21)), + (4,2--4,21), Yes, { ArrowRange = Some (4,17--4,19) + BarRange = Some (4,0--4,1) })], + (3,0--4,21), { MatchKeyword = (3,0--3,5) + WithKeyword = (3,8--3,12) }), (3,0--4,21))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--4,21), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(4,15)-(4,16) parse error Unexpected symbol ')' in pattern diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 08.fs b/tests/service/data/SyntaxTree/Pattern/Named field 08.fs new file mode 100644 index 00000000000..cad1308ead9 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 08.fs @@ -0,0 +1,4 @@ +module Module + +match 1 with +| A(a = _, b) -> 2 diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 08.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 08.fs.bsl new file mode 100644 index 00000000000..535db9ccc01 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 08.fs.bsl @@ -0,0 +1,28 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 08.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,12), Const (Int32 1, (3,6--3,7)), + [SynMatchClause + (LongIdent + (SynLongIdent ([A], [], [None]), None, None, + NamePatPairs + ([(a, Some (4,6--4,7), Wild (4,8--4,9)); + (b, None, + FromParseError (Wild (4,12--4,12), (4,12--4,12)))], + (4,4--4,13), { ParenRange = (4,3--4,13) }), None, + (4,2--4,13)), None, Const (Int32 2, (4,17--4,18)), + (4,2--4,18), Yes, { ArrowRange = Some (4,14--4,16) + BarRange = Some (4,0--4,1) })], + (3,0--4,18), { MatchKeyword = (3,0--3,5) + WithKeyword = (3,8--3,12) }), (3,0--4,18))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--4,18), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(4,12)-(4,13) parse error Unexpected symbol ')' in pattern. Expected '=' or other token. diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 09.fs b/tests/service/data/SyntaxTree/Pattern/Named field 09.fs new file mode 100644 index 00000000000..505049e223d --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 09.fs @@ -0,0 +1,4 @@ +module Module + +match 1 with +| A(a = _,) -> 2 diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 09.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 09.fs.bsl new file mode 100644 index 00000000000..aeb03467c47 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 09.fs.bsl @@ -0,0 +1,24 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 09.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,12), Const (Int32 1, (3,6--3,7)), + [SynMatchClause + (LongIdent + (SynLongIdent ([A], [], [None]), None, None, + NamePatPairs + ([(a, Some (4,6--4,7), Wild (4,8--4,9))], (4,4--4,10), + { ParenRange = (4,3--4,11) }), None, (4,2--4,11)), + None, Const (Int32 2, (4,15--4,16)), (4,2--4,16), Yes, + { ArrowRange = Some (4,12--4,14) + BarRange = Some (4,0--4,1) })], (3,0--4,16), + { MatchKeyword = (3,0--3,5) + WithKeyword = (3,8--3,12) }), (3,0--4,16))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--4,16), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 10.fs b/tests/service/data/SyntaxTree/Pattern/Named field 10.fs new file mode 100644 index 00000000000..55e7893670b --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 10.fs @@ -0,0 +1,4 @@ +module Module + +match 1 with +| A(a = _, , c = _) -> 2 \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 10.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 10.fs.bsl new file mode 100644 index 00000000000..d3b5409b216 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 10.fs.bsl @@ -0,0 +1,27 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 10.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,12), Const (Int32 1, (3,6--3,7)), + [SynMatchClause + (LongIdent + (SynLongIdent ([A], [], [None]), None, None, + NamePatPairs + ([(a, Some (4,6--4,7), Wild (4,8--4,9)); + (c, Some (4,15--4,16), Wild (4,17--4,18))], + (4,4--4,19), { ParenRange = (4,3--4,19) }), None, + (4,2--4,19)), None, Const (Int32 2, (4,23--4,24)), + (4,2--4,24), Yes, { ArrowRange = Some (4,20--4,22) + BarRange = Some (4,0--4,1) })], + (3,0--4,24), { MatchKeyword = (3,0--3,5) + WithKeyword = (3,8--3,12) }), (3,0--4,24))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--4,24), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) + +(4,11)-(4,12) parse error Expecting pattern diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 11.fs b/tests/service/data/SyntaxTree/Pattern/Named field 11.fs new file mode 100644 index 00000000000..1fb57e9ba25 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 11.fs @@ -0,0 +1,6 @@ +module Module + +match shape with +| Rectangle(width = w, length = l) -> w * l +| Circle(radius = r) -> System.Math.PI * r ** 2. +| Prism(width = w, length = l, height = h) -> w * l * h \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 11.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 11.fs.bsl new file mode 100644 index 00000000000..8f54a913f25 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 11.fs.bsl @@ -0,0 +1,119 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 11.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,16), Ident shape, + [SynMatchClause + (LongIdent + (SynLongIdent ([Rectangle], [], [None]), None, None, + NamePatPairs + ([(width, Some (4,18--4,19), + Named + (SynIdent (w, None), false, None, (4,20--4,21))); + (length, Some (4,30--4,31), + Named + (SynIdent (l, None), false, None, (4,32--4,33)))], + (4,12--4,34), { ParenRange = (4,11--4,34) }), None, + (4,2--4,34)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (4,40--4,41)), Ident w, (4,38--4,41)), Ident l, + (4,38--4,43)), (4,2--4,43), Yes, + { ArrowRange = Some (4,35--4,37) + BarRange = Some (4,0--4,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Circle], [], [None]), None, None, + NamePatPairs + ([(radius, Some (5,16--5,17), + Named + (SynIdent (r, None), false, None, (5,18--5,19)))], + (5,9--5,20), { ParenRange = (5,8--5,20) }), None, + (5,2--5,20)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (5,39--5,40)), + LongIdent + (false, + SynLongIdent + ([System; Math; PI], + [(5,30--5,31); (5,35--5,36)], + [None; None; None]), None, (5,24--5,38)), + (5,24--5,40)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Exponentiation], [], + [Some (OriginalNotation "**")]), None, + (5,43--5,45)), Ident r, (5,41--5,45)), + Const (Double 2.0, (5,46--5,48)), (5,41--5,48)), + (5,24--5,48)), (5,2--5,48), Yes, + { ArrowRange = Some (5,21--5,23) + BarRange = Some (5,0--5,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Prism], [], [None]), None, None, + NamePatPairs + ([(width, Some (6,14--6,15), + Named + (SynIdent (w, None), false, None, (6,16--6,17))); + (length, Some (6,26--6,27), + Named + (SynIdent (l, None), false, None, (6,28--6,29))); + (height, Some (6,38--6,39), + Named + (SynIdent (h, None), false, None, (6,40--6,41)))], + (6,8--6,42), { ParenRange = (6,7--6,42) }), None, + (6,2--6,42)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,52--6,53)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,48--6,49)), Ident w, (6,46--6,49)), + Ident l, (6,46--6,51)), (6,46--6,53)), Ident h, + (6,46--6,55)), (6,2--6,55), Yes, + { ArrowRange = Some (6,43--6,45) + BarRange = Some (6,0--6,1) })], (3,0--6,55), + { MatchKeyword = (3,0--3,5) + WithKeyword = (3,12--3,16) }), (3,0--6,55))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,55), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 12.fs b/tests/service/data/SyntaxTree/Pattern/Named field 12.fs new file mode 100644 index 00000000000..46e83e7ca82 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 12.fs @@ -0,0 +1,6 @@ +module Module + +match shape with +| Rectangle(width = w; length = l) -> w * l +| Circle(radius = r) -> System.Math.PI * r ** 2. +| Prism(width = w; length = l; height = h) -> w * l * h \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 12.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 12.fs.bsl new file mode 100644 index 00000000000..383860c8ae7 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 12.fs.bsl @@ -0,0 +1,119 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 12.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,16), Ident shape, + [SynMatchClause + (LongIdent + (SynLongIdent ([Rectangle], [], [None]), None, None, + NamePatPairs + ([(width, Some (4,18--4,19), + Named + (SynIdent (w, None), false, None, (4,20--4,21))); + (length, Some (4,30--4,31), + Named + (SynIdent (l, None), false, None, (4,32--4,33)))], + (4,12--4,34), { ParenRange = (4,11--4,34) }), None, + (4,2--4,34)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (4,40--4,41)), Ident w, (4,38--4,41)), Ident l, + (4,38--4,43)), (4,2--4,43), Yes, + { ArrowRange = Some (4,35--4,37) + BarRange = Some (4,0--4,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Circle], [], [None]), None, None, + NamePatPairs + ([(radius, Some (5,16--5,17), + Named + (SynIdent (r, None), false, None, (5,18--5,19)))], + (5,9--5,20), { ParenRange = (5,8--5,20) }), None, + (5,2--5,20)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (5,39--5,40)), + LongIdent + (false, + SynLongIdent + ([System; Math; PI], + [(5,30--5,31); (5,35--5,36)], + [None; None; None]), None, (5,24--5,38)), + (5,24--5,40)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Exponentiation], [], + [Some (OriginalNotation "**")]), None, + (5,43--5,45)), Ident r, (5,41--5,45)), + Const (Double 2.0, (5,46--5,48)), (5,41--5,48)), + (5,24--5,48)), (5,2--5,48), Yes, + { ArrowRange = Some (5,21--5,23) + BarRange = Some (5,0--5,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Prism], [], [None]), None, None, + NamePatPairs + ([(width, Some (6,14--6,15), + Named + (SynIdent (w, None), false, None, (6,16--6,17))); + (length, Some (6,26--6,27), + Named + (SynIdent (l, None), false, None, (6,28--6,29))); + (height, Some (6,38--6,39), + Named + (SynIdent (h, None), false, None, (6,40--6,41)))], + (6,8--6,42), { ParenRange = (6,7--6,42) }), None, + (6,2--6,42)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,52--6,53)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,48--6,49)), Ident w, (6,46--6,49)), + Ident l, (6,46--6,51)), (6,46--6,53)), Ident h, + (6,46--6,55)), (6,2--6,55), Yes, + { ArrowRange = Some (6,43--6,45) + BarRange = Some (6,0--6,1) })], (3,0--6,55), + { MatchKeyword = (3,0--3,5) + WithKeyword = (3,12--3,16) }), (3,0--6,55))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,55), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set [])) diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 13.fs b/tests/service/data/SyntaxTree/Pattern/Named field 13.fs new file mode 100644 index 00000000000..83d7be732b0 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 13.fs @@ -0,0 +1,6 @@ +module Module + +match shape with +| Rectangle(width = w, length = l) -> w * l +| Circle(radius = r) -> System.Math.PI * r ** 2. +| Prism(width = w; length = l, height = h) -> w * l * h \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Pattern/Named field 13.fs.bsl b/tests/service/data/SyntaxTree/Pattern/Named field 13.fs.bsl new file mode 100644 index 00000000000..c8645371120 --- /dev/null +++ b/tests/service/data/SyntaxTree/Pattern/Named field 13.fs.bsl @@ -0,0 +1,119 @@ +ImplFile + (ParsedImplFileInput + ("/root/Pattern/Named field 13.fs", false, QualifiedNameOfFile Module, [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Expr + (Match + (Yes (3,0--3,16), Ident shape, + [SynMatchClause + (LongIdent + (SynLongIdent ([Rectangle], [], [None]), None, None, + NamePatPairs + ([(width, Some (4,18--4,19), + Named + (SynIdent (w, None), false, None, (4,20--4,21))); + (length, Some (4,30--4,31), + Named + (SynIdent (l, None), false, None, (4,32--4,33)))], + (4,12--4,34), { ParenRange = (4,11--4,34) }), None, + (4,2--4,34)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (4,40--4,41)), Ident w, (4,38--4,41)), Ident l, + (4,38--4,43)), (4,2--4,43), Yes, + { ArrowRange = Some (4,35--4,37) + BarRange = Some (4,0--4,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Circle], [], [None]), None, None, + NamePatPairs + ([(radius, Some (5,16--5,17), + Named + (SynIdent (r, None), false, None, (5,18--5,19)))], + (5,9--5,20), { ParenRange = (5,8--5,20) }), None, + (5,2--5,20)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (5,39--5,40)), + LongIdent + (false, + SynLongIdent + ([System; Math; PI], + [(5,30--5,31); (5,35--5,36)], + [None; None; None]), None, (5,24--5,38)), + (5,24--5,40)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Exponentiation], [], + [Some (OriginalNotation "**")]), None, + (5,43--5,45)), Ident r, (5,41--5,45)), + Const (Double 2.0, (5,46--5,48)), (5,41--5,48)), + (5,24--5,48)), (5,2--5,48), Yes, + { ArrowRange = Some (5,21--5,23) + BarRange = Some (5,0--5,1) }); + SynMatchClause + (LongIdent + (SynLongIdent ([Prism], [], [None]), None, None, + NamePatPairs + ([(width, Some (6,14--6,15), + Named + (SynIdent (w, None), false, None, (6,16--6,17))); + (length, Some (6,26--6,27), + Named + (SynIdent (l, None), false, None, (6,28--6,29))); + (height, Some (6,38--6,39), + Named + (SynIdent (h, None), false, None, (6,40--6,41)))], + (6,8--6,42), { ParenRange = (6,7--6,42) }), None, + (6,2--6,42)), None, + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,52--6,53)), + App + (NonAtomic, false, + App + (NonAtomic, true, + LongIdent + (false, + SynLongIdent + ([op_Multiply], [], + [Some (OriginalNotation "*")]), None, + (6,48--6,49)), Ident w, (6,46--6,49)), + Ident l, (6,46--6,51)), (6,46--6,53)), Ident h, + (6,46--6,55)), (6,2--6,55), Yes, + { ArrowRange = Some (6,43--6,45) + BarRange = Some (6,0--6,1) })], (3,0--6,55), + { MatchKeyword = (3,0--3,5) + WithKeyword = (3,12--3,16) }), (3,0--6,55))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,55), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + WarnDirectives = [] + CodeComments = [] }, set []))