From d680c0c95f460303d2705919022ff39f7051daf0 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Mon, 3 Jun 2019 13:33:01 -0700 Subject: [PATCH] Enable LangVersion on 'Add missing case for underscore in for _ feature --- src/fsharp/LanguageFeatures.fs | 6 +-- src/fsharp/LanguageFeatures.fsi | 3 +- src/fsharp/pars.fsy | 9 ++-- tests/fsharp/core/forexpression/test.fsx | 13 ------ .../core/forexpression/version46/test.fs | 41 ++++++++++++++++++ .../core/forexpression/version47/test.fs | 43 +++++++++++++++++++ tests/fsharp/single-test.fs | 2 +- 7 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 tests/fsharp/core/forexpression/version46/test.fs create mode 100644 tests/fsharp/core/forexpression/version47/test.fs diff --git a/src/fsharp/LanguageFeatures.fs b/src/fsharp/LanguageFeatures.fs index 15a30f6b614..a51e21843ee 100644 --- a/src/fsharp/LanguageFeatures.fs +++ b/src/fsharp/LanguageFeatures.fs @@ -22,8 +22,7 @@ type LanguageFeature = | LanguageVersion46 = 0 | LanguageVersion47 = 1 | SingleUnderscorePattern = 2 - | Nullness = 1000 - | ScriptingPackageManagement = 1001 + | WildCardInForLoop = 3 /// LanguageVersion management type LanguageVersion (specifiedVersion) = @@ -44,9 +43,8 @@ type LanguageVersion (specifiedVersion) = // Add new LanguageVersions here ... LanguageFeature.LanguageVersion47, 4.7m LanguageFeature.LanguageVersion46, 4.6m - LanguageFeature.Nullness, previewVersion - LanguageFeature.ScriptingPackageManagement, previewVersion LanguageFeature.SingleUnderscorePattern, previewVersion + LanguageFeature.WildCardInForLoop, previewVersion // Add new LanguageFeatures here ... |] diff --git a/src/fsharp/LanguageFeatures.fsi b/src/fsharp/LanguageFeatures.fsi index a43ac242768..63ad5915c20 100644 --- a/src/fsharp/LanguageFeatures.fsi +++ b/src/fsharp/LanguageFeatures.fsi @@ -9,8 +9,7 @@ type LanguageFeature = | LanguageVersion46 = 0 | LanguageVersion47 = 1 | SingleUnderscorePattern = 2 - | Nullness = 1000 - | ScriptingPackageManagement = 1001 + | WildCardInForLoop = 3 /// LanguageVersion management type LanguageVersion = diff --git a/src/fsharp/pars.fsy b/src/fsharp/pars.fsy index d95f8ce5ce6..7984f55e5ee 100644 --- a/src/fsharp/pars.fsy +++ b/src/fsharp/pars.fsy @@ -130,10 +130,11 @@ let mkDefnBindings (mWhole,BindingSetPreAttrs(_,isRec,isUse,declsPreAttrs,_bindi let attrDecls = if not (isNil freeAttrs) then [ SynModuleDecl.Attributes (freeAttrs,attrsm) ] else [] attrDecls @ letDecls -let idOfPat m p = +let idOfPat (parseState:IParseState) m p = match p with - | SynPat.Wild r -> 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 437f62b971c..0fada85b01b 100644 --- a/tests/fsharp/core/forexpression/test.fsx +++ b/tests/fsharp/core/forexpression/test.fsx @@ -110,18 +110,7 @@ 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 - -// usingWildcard counts using a wildcard in a for loop -let usingWildcard () = - let mutable sum = 0 - for _ = 0 to count do - sum <- sum + 1 sum let arraySum = sumOverArray () @@ -132,7 +121,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 +130,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 00000000000..c2042a9f0c1 --- /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 00000000000..868a4757ce2 --- /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 0b481198079..c1707f619e2 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