From 218ca54841015eb089043057bae275e062e461c2 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Sun, 2 Jun 2019 19:22:15 -0700 Subject: [PATCH] Enable LangVersion on 'Add missing case for underscore in for _ feature --- FSharpBuild.Directory.Build.targets | 5 +++ src/fsharp/LanguageFeatures.fs | 6 +-- src/fsharp/LanguageFeatures.fsi | 3 +- src/fsharp/pars.fsy | 9 ++-- tests/fsharp/core/forexpression/test.fsx | 12 +++--- .../core/forexpression/version46/test.fs | 41 ++++++++++++++++++ .../core/forexpression/version47/test.fs | 43 +++++++++++++++++++ tests/fsharp/single-test.fs | 2 +- 8 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 tests/fsharp/core/forexpression/version46/test.fs create mode 100644 tests/fsharp/core/forexpression/version47/test.fs diff --git a/FSharpBuild.Directory.Build.targets b/FSharpBuild.Directory.Build.targets index d87d68d36c7b..22379d8d1cb4 100644 --- a/FSharpBuild.Directory.Build.targets +++ b/FSharpBuild.Directory.Build.targets @@ -5,6 +5,11 @@ + + + $(DefineConstants);LANGVERSION_ATLEAST_4_7 + + mkSynId r "_" - | SynPat.Named (SynPat.Wild _,id,false,_,_) -> id + | SynPat.Wild r when parseState.LexBuffer.SupportsFeature LanguageFeature.WildCardInForLoop -> + mkSynId r "_" + | SynPat.Named (SynPat.Wild _,id,false,_,_) -> id | SynPat.LongIdent(LongIdentWithDots([id],_),_,None, SynConstructorArgs.Pats [], None,_) -> id | _ -> raiseParseErrorAt m (FSComp.SR.parsIntegerForLoopRequiresSimpleIdentifier()) @@ -3992,7 +3993,7 @@ forLoopBinder: forLoopRange: | parenPattern EQUALS declExpr forLoopDirection declExpr - { idOfPat (rhs parseState 1) $1,$3,$4,$5 } + { idOfPat parseState (rhs parseState 1) $1,$3,$4,$5 } | parenPattern EQUALS rangeSequenceExpr { raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsUnexpectedSymbolEqualsInsteadOfIn()) } diff --git a/tests/fsharp/core/forexpression/test.fsx b/tests/fsharp/core/forexpression/test.fsx index 437f62b971c4..e9aace32a533 100644 --- a/tests/fsharp/core/forexpression/test.fsx +++ b/tests/fsharp/core/forexpression/test.fsx @@ -1,5 +1,5 @@ #if TESTS_AS_APP -module Core_forexpression +module Core_forexpression_47 #endif let failures = ref false @@ -110,13 +110,10 @@ let sumOverRange () = let sumOverString () = let mutable sum = 0 for i in testString do -#if NETCOREAPP - sum <- sum + ((int (i :?> char)) - (int '0')) -#else sum <- sum + ((int i) - (int '0')) -#endif sum +#if LANGVERSION_ATLEAST_4_7 // usingWildcard counts using a wildcard in a for loop let usingWildcard () = let mutable sum = 0 @@ -124,6 +121,9 @@ let usingWildcard () = sum <- sum + 1 sum +do test "wildCard" (expectedWildCard = usingWildcard () ) +#endif + let arraySum = sumOverArray () let seqSum = sumOverSeq () let dictionarySum = sumOverDictionary () @@ -132,7 +132,6 @@ let listSum = sumOverList () let ilistSum = sumOverIList () let rangeSum = sumOverRange () let stringSum = sumOverString () -let wildCard = usingWildcard () do test "arraySum" (expectedArraySum = arraySum ) do test "seqSum" (expectedArraySum = seqSum ) @@ -142,7 +141,6 @@ do test "listSum" (expectedArraySum = listSum ) do test "ilistSum" (expectedArraySum = ilistSum ) do test "rangeSum" (expectedRangeSum = rangeSum ) do test "stringSum" (expectedStringSum = stringSum ) -do test "wildCard" (expectedWildCard = wildCard ) #if TESTS_AS_APP let RUN() = !failures diff --git a/tests/fsharp/core/forexpression/version46/test.fs b/tests/fsharp/core/forexpression/version46/test.fs new file mode 100644 index 000000000000..c2042a9f0c18 --- /dev/null +++ b/tests/fsharp/core/forexpression/version46/test.fs @@ -0,0 +1,41 @@ +//An integer for loop must use a simple identifier +module Global + +let failures = ref [] + +let report_failure (s : string) = + stderr.Write" NO: " + stderr.WriteLine s + failures := !failures @ [s] + +let test (s : string) b = + stderr.Write(s) + if b then stderr.WriteLine " OK" + else report_failure (s) + +let check s b1 b2 = test s (b1 = b2) + +// usingWildcard counts using a wildcard in a for loop +let usingWildcard () = + let mutable sum = 0 + for _ = 0 to count do + sum <- sum + 1 + + printfn "usingWildcards expected to produce sum of 4 : sum='%d'"sum + +do test "wildCard" (4 = usingWildcard () ) + +#if TESTS_AS_APP +let RUN() = !failures +#else +let aa = + match !failures with + | [] -> + stdout.WriteLine "Test Passed" + System.IO.File.WriteAllText("test.ok","ok") + exit 0 + | _ -> + stdout.WriteLine "Test Failed" + exit 1 +#endif + diff --git a/tests/fsharp/core/forexpression/version47/test.fs b/tests/fsharp/core/forexpression/version47/test.fs new file mode 100644 index 000000000000..868a4757ce24 --- /dev/null +++ b/tests/fsharp/core/forexpression/version47/test.fs @@ -0,0 +1,43 @@ +//usingWildcards expected to produce sum of 4 : sum='4' +#if TESTS_AS_APP +module Core_forexpression_47 +#endif + +let failures = ref [] + +let report_failure (s : string) = + stderr.Write" NO: " + stderr.WriteLine s + failures := !failures @ [s] + +let test (s : string) b = + stderr.Write(s) + if b then stderr.WriteLine " OK" + else report_failure (s) + +let check s b1 b2 = test s (b1 = b2) + +// usingWildcard counts using a wildcard in a for loop +let usingWildcard () = + let mutable sum = 0 + for _ = 0 to count do + sum <- sum + 1 + + printfn "usingWildcards expected to produce sum of 4 : sum='%d'"sum + +do test "wildCard" (4 = usingWildcard () ) + +#if TESTS_AS_APP +let RUN() = !failures +#else +let aa = + match !failures with + | [] -> + stdout.WriteLine "Test Passed" + System.IO.File.WriteAllText("test.ok","ok") + exit 0 + | _ -> + stdout.WriteLine "Test Failed" + exit 1 +#endif + diff --git a/tests/fsharp/single-test.fs b/tests/fsharp/single-test.fs index 0b481198079c..c1707f619e2f 100644 --- a/tests/fsharp/single-test.fs +++ b/tests/fsharp/single-test.fs @@ -298,7 +298,7 @@ let singleTestBuildAndRunCore cfg copyFiles p languageVersion = result <- true finally if result <> false then - Directory.Delete(directory, true) + try Directory.Delete(directory, true) with _ -> () else printfn "Configuration: %s" cfg.Directory printfn "Directory: %s" directory