From 9931ab362ef8b2f54b1a3793682acc0b06d32272 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Mon, 3 Jun 2019 02:30:48 -0700 Subject: [PATCH] dd langversion support for whitespace indent feature --- .gitignore | 4 +- src/fsharp/LanguageFeatures.fs | 2 + src/fsharp/LanguageFeatures.fsi | 1 + src/fsharp/LexFilter.fs | 7 +- tests/fsharp/HandleExpects.fs | 2 +- tests/fsharp/core/indent/version46/test.fsx | 121 ++++++++++++++++++++ tests/fsharp/core/indent/version47/test.fsx | 93 +++++++++++++++ tests/fsharp/tests.fs | 9 +- tests/fsharp/typecheck/sigs/neg77.bsl | 12 -- tests/fsharp/typecheck/sigs/neg77.fsx | 54 --------- tests/fsharp/typecheck/sigs/neg77.vsbsl | 24 ---- 11 files changed, 234 insertions(+), 95 deletions(-) create mode 100644 tests/fsharp/core/indent/version46/test.fsx create mode 100644 tests/fsharp/core/indent/version47/test.fsx diff --git a/.gitignore b/.gitignore index e6feea6dfc9..d48410b8737 100644 --- a/.gitignore +++ b/.gitignore @@ -100,7 +100,9 @@ ossreadme*.txt *.log *.jrs *.chk -*.bak +*.bak +*.vserr +*.err *.orig *.mdf *.ldf diff --git a/src/fsharp/LanguageFeatures.fs b/src/fsharp/LanguageFeatures.fs index 15a30f6b614..7077ba3a03c 100644 --- a/src/fsharp/LanguageFeatures.fs +++ b/src/fsharp/LanguageFeatures.fs @@ -22,6 +22,7 @@ type LanguageFeature = | LanguageVersion46 = 0 | LanguageVersion47 = 1 | SingleUnderscorePattern = 2 + | RelaxWhitespace = 4 | Nullness = 1000 | ScriptingPackageManagement = 1001 @@ -44,6 +45,7 @@ type LanguageVersion (specifiedVersion) = // Add new LanguageVersions here ... LanguageFeature.LanguageVersion47, 4.7m LanguageFeature.LanguageVersion46, 4.6m + LanguageFeature.RelaxWhitespace, previewVersion LanguageFeature.Nullness, previewVersion LanguageFeature.ScriptingPackageManagement, previewVersion LanguageFeature.SingleUnderscorePattern, previewVersion diff --git a/src/fsharp/LanguageFeatures.fsi b/src/fsharp/LanguageFeatures.fsi index a43ac242768..d6b291be562 100644 --- a/src/fsharp/LanguageFeatures.fsi +++ b/src/fsharp/LanguageFeatures.fsi @@ -9,6 +9,7 @@ type LanguageFeature = | LanguageVersion46 = 0 | LanguageVersion47 = 1 | SingleUnderscorePattern = 2 + | RelaxWhitespace = 4 | Nullness = 1000 | ScriptingPackageManagement = 1001 diff --git a/src/fsharp/LexFilter.fs b/src/fsharp/LexFilter.fs index a125a64d7bf..e37b0c35b1b 100755 --- a/src/fsharp/LexFilter.fs +++ b/src/fsharp/LexFilter.fs @@ -12,9 +12,9 @@ open FSharp.Compiler.AbstractIL.Internal.Library open FSharp.Compiler.AbstractIL.Diagnostics open FSharp.Compiler.Ast open FSharp.Compiler.ErrorLogger +open FSharp.Compiler.Features open FSharp.Compiler.Parser open FSharp.Compiler.Lexhelp - let debug = false let stringOfPos (p: Position) = sprintf "(%d:%d)" p.OriginalLine p.Column @@ -765,13 +765,16 @@ type LexFilterImpl (lightSyntaxStatus: LightSyntaxStatus, compilingFsLib, lexer, // 'type C = interface ... ' limited by 'type' // 'type C = struct ... ' limited by 'type' | _, (CtxtParen ((CLASS | STRUCT | INTERFACE), _) :: CtxtSeqBlock _ :: (CtxtTypeDefns _ as limitCtxt) :: _) + -> PositionWithColumn(limitCtxt.StartPos, limitCtxt.StartCol + 1) + // 'type C(' limited by 'type' | _, (CtxtSeqBlock _ :: CtxtParen(LPAREN, _) :: (CtxtTypeDefns _ as limitCtxt) :: _ ) // 'static member C(' limited by 'static', likewise others | _, (CtxtSeqBlock _ :: CtxtParen(LPAREN, _) :: (CtxtMemberHead _ as limitCtxt) :: _ ) // 'static member P with get() = ' limited by 'static', likewise others | _, (CtxtWithAsLet _ :: (CtxtMemberHead _ as limitCtxt) :: _ ) - -> PositionWithColumn(limitCtxt.StartPos, limitCtxt.StartCol + 1) + when lexbuf.SupportsFeature LanguageFeature.RelaxWhitespace + -> PositionWithColumn(limitCtxt.StartPos, limitCtxt.StartCol + 1) // REVIEW: document these | _, (CtxtSeqBlock _ :: CtxtParen((BEGIN | LPAREN | LBRACK | LBRACK_BAR), _) :: CtxtVanilla _ :: (CtxtSeqBlock _ as limitCtxt) :: _) diff --git a/tests/fsharp/HandleExpects.fs b/tests/fsharp/HandleExpects.fs index 9a11f90adc3..76c5267bacf 100644 --- a/tests/fsharp/HandleExpects.fs +++ b/tests/fsharp/HandleExpects.fs @@ -44,7 +44,7 @@ let stripFromFileExpectations source = else expect.Replace(content, "") let rdr = XmlReader.Create(new StringReader(nocontentxpect)) - let mutable element = { status="success"; id = ""; span = ""; pattern = content; matched = false; line=nocontentxpect } + let mutable element = { status="success"; id = ""; span = ""; pattern = content; matched = false; line=expect } let mutable insideExpects = false let mutable foundOne = false try diff --git a/tests/fsharp/core/indent/version46/test.fsx b/tests/fsharp/core/indent/version46/test.fsx new file mode 100644 index 00000000000..7afc6f1dd51 --- /dev/null +++ b/tests/fsharp/core/indent/version46/test.fsx @@ -0,0 +1,121 @@ +//Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions. + + +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) + +type OffsideCheck(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = 1 + +module M = + type OffsideCheck(a:int, + b:int, c:int, // 4.6 warning: 4.7 warning + d:int, e:int, + f:int) = + class end + +module M2 = + type OffsideCheck() = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 warning + d:int, e:int, + f:int) = 1 + +type C() = + static member P with get() = + 1 // 4.6 warning: 4.7 no warning + +module M3 = + type C() = + static member P with get() = + 1 // warning + +type OffsideCheck2(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = 1 + +type OffsideCheck3(a:int, + b:int, c:int, // no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = 1 + +#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/indent/version47/test.fsx b/tests/fsharp/core/indent/version47/test.fsx new file mode 100644 index 00000000000..97b226e9e52 --- /dev/null +++ b/tests/fsharp/core/indent/version47/test.fsx @@ -0,0 +1,93 @@ +//Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions. +//Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions. + + +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) + +type OffsideCheck(a:int, + b:int, c:int, // no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // no warning + d:int, e:int, + f:int) = 1 + +module M = + type OffsideCheck(a:int, + b:int, c:int, // 4.6 warning: 4.7 warning + d:int, e:int, + f:int) = + class end + +module M2 = + type OffsideCheck() = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 warning + d:int, e:int, + f:int) = 1 + +type C() = + static member P with get() = + 1 // 4.6 warning: 4.7 no warning + +module M3 = + type C() = + static member P with get() = + 1 // warning + +type OffsideCheck2(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = 1 + +type OffsideCheck3(a:int, + b:int, c:int, // no warning + d:int, e:int, + f:int) = + static member M(a:int, + b:int, c:int, // 4.6 warning: 4.7 no warning + d:int, e:int, + f:int) = 1 + +#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/tests.fs b/tests/fsharp/tests.fs index 01bc3f954ea..cd9a7c8b687 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1811,6 +1811,13 @@ module VersionTests = [] let ``member-selfidentifier-version4.7``() = singleTestBuildAndRunVersion "core/members/self-identifier/version47" FSC_BUILDONLY "preview" + [] + let ``indent-version4.6``() = singleTestBuildAndRunVersion "core/indent/version46" FSC_BUILDONLY "4.6" + + [] + let ``indent-version4.7``() = singleTestBuildAndRunVersion "core/indent/version47" FSC_BUILDONLY "preview" + + #if !FSHARP_SUITE_DRIVES_CORECLR_TESTS module ToolsTests = @@ -1820,7 +1827,7 @@ module ToolsTests = let cfg = testConfig "tools/bundle" fsc cfg "%s --progress --standalone -o:test-one-fsharp-module.exe -g" cfg.fsc_flags ["test-one-fsharp-module.fs"] - + peverify cfg "test-one-fsharp-module.exe" fsc cfg "%s -a -o:test_two_fsharp_modules_module_1.dll -g" cfg.fsc_flags ["test_two_fsharp_modules_module_1.fs"] diff --git a/tests/fsharp/typecheck/sigs/neg77.bsl b/tests/fsharp/typecheck/sigs/neg77.bsl index 3598ff0c935..922e6b66950 100644 --- a/tests/fsharp/typecheck/sigs/neg77.bsl +++ b/tests/fsharp/typecheck/sigs/neg77.bsl @@ -4,15 +4,3 @@ neg77.fsx(134,15,134,16): parse error FS0058: Possible incorrect indentation: th neg77.fsx(134,15,134,16): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (133:19). Try indenting this token further or using standard formatting conventions. neg77.fsx(134,15,134,16): parse error FS0010: Unexpected symbol '|' in expression - -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. diff --git a/tests/fsharp/typecheck/sigs/neg77.fsx b/tests/fsharp/typecheck/sigs/neg77.fsx index 2f38101f2d6..c354321cde8 100644 --- a/tests/fsharp/typecheck/sigs/neg77.fsx +++ b/tests/fsharp/typecheck/sigs/neg77.fsx @@ -243,60 +243,6 @@ do Application.Run(form) #endif -open System - -type OffsideCheck(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = - static member M(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = 1 - -module M = - type OffsideCheck(a:int, - b:int, c:int, // warning - d:int, e:int, - f:int) = - class end - -module M2 = - type OffsideCheck() = - static member M(a:int, - b:int, c:int, // warning - d:int, e:int, - f:int) = 1 - -type C() = - static member P with get() = - 1 // no warning - -module M3 = - type C() = - static member P with get() = - 1 // warning - - -type OffsideCheck2(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = - static member M(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = 1 - -type OffsideCheck3(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = - static member M(a:int, - b:int, c:int, // no warning - d:int, e:int, - f:int) = 1 - - diff --git a/tests/fsharp/typecheck/sigs/neg77.vsbsl b/tests/fsharp/typecheck/sigs/neg77.vsbsl index 32adc1f3b96..44832298057 100644 --- a/tests/fsharp/typecheck/sigs/neg77.vsbsl +++ b/tests/fsharp/typecheck/sigs/neg77.vsbsl @@ -5,34 +5,10 @@ neg77.fsx(134,15,134,16): parse error FS0058: Possible incorrect indentation: th neg77.fsx(134,15,134,16): parse error FS0010: Unexpected symbol '|' in expression -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. - neg77.fsx(134,15,134,16): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (133:19). Try indenting this token further or using standard formatting conventions. neg77.fsx(134,15,134,16): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (133:19). Try indenting this token further or using standard formatting conventions. neg77.fsx(134,15,134,16): parse error FS0010: Unexpected symbol '|' in expression -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(259,3,259,4): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (258:5). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(267,7,267,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (266:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. - -neg77.fsx(278,7,278,8): parse error FS0058: Possible incorrect indentation: this token is offside of context started at position (277:9). Try indenting this token further or using standard formatting conventions. - neg77.fsx(153,75,153,79): typecheck error FS0001: The type 'Planet * 'a' is not compatible with the type 'Planet'