Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Langversion to control relaxwhitespace language feature #6933

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ ossreadme*.txt
*.log
*.jrs
*.chk
*.bak
*.bak
*.vserr
*.err
*.orig
*.mdf
*.ldf
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type LanguageFeature =
| LanguageVersion47 = 1
| SingleUnderscorePattern = 2
| WildCardInForLoop = 3
| RelaxWhitespace = 4

/// LanguageVersion management
type LanguageVersion (specifiedVersion) =
Expand All @@ -45,6 +46,7 @@ type LanguageVersion (specifiedVersion) =
LanguageFeature.LanguageVersion46, 4.6m
LanguageFeature.SingleUnderscorePattern, previewVersion
LanguageFeature.WildCardInForLoop, previewVersion
LanguageFeature.RelaxWhitespace, previewVersion

// Add new LanguageFeatures here ...
|]
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type LanguageFeature =
| LanguageVersion47 = 1
| SingleUnderscorePattern = 2
| WildCardInForLoop = 3
| RelaxWhitespace = 4

/// LanguageVersion management
type LanguageVersion =
Expand Down
7 changes: 5 additions & 2 deletions src/fsharp/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) :: _)
Expand Down
2 changes: 1 addition & 1 deletion tests/fsharp/HandleExpects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
121 changes: 121 additions & 0 deletions tests/fsharp/core/indent/version46/test.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//<Expects id="FS0058" status="warning" span="(60,9)">Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(60,9)">Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(64,9)">Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(64,9)">Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(70,3)">Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(70,3)">Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(78,7)">Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(78,7)">Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(84,7)">Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(84,7)">Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(89,7)">Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(89,7)">Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(92,5)">Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(92,5)">Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(96,9)">Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(96,9)">Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(101,2)">Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(101,2)">Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(105,6)">Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(105,6)">Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(60,9)">Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(60,9)">Possible incorrect indentation: this token is offside of context started at position \(59:19\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(64,9)">Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(64,9)">Possible incorrect indentation: this token is offside of context started at position \(63:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(70,3)">Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(70,3)">Possible incorrect indentation: this token is offside of context started at position \(69:23\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(78,7)">Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(78,7)">Possible incorrect indentation: this token is offside of context started at position \(77:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(84,7)">Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(84,7)">Possible incorrect indentation: this token is offside of context started at position \(83:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(89,7)">Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(89,7)">Possible incorrect indentation: this token is offside of context started at position \(88:25\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(92,5)">Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(92,5)">Possible incorrect indentation: this token is offside of context started at position \(91:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(96,9)">Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(96,9)">Possible incorrect indentation: this token is offside of context started at position \(95:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(101,2)">Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(101,2)">Possible incorrect indentation: this token is offside of context started at position \(100:20\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(105,6)">Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(105,6)">Possible incorrect indentation: this token is offside of context started at position \(104:21\). Try indenting this token further or using standard formatting conventions.</Expects>


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
93 changes: 93 additions & 0 deletions tests/fsharp/core/indent/version47/test.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//<Expects id="FS0058" status="warning" span="(42,3)">Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(42,3)">Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(50,7)">Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(50,7)">Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(61,7)">Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(61,7)">Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(42,3)">Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(42,3)">Possible incorrect indentation: this token is offside of context started at position \(41:5\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(50,7)">Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(50,7)">Possible incorrect indentation: this token is offside of context started at position \(49:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(61,7)">Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions.</Expects>
//<Expects id="FS0058" status="warning" span="(61,7)">Possible incorrect indentation: this token is offside of context started at position \(60:9\). Try indenting this token further or using standard formatting conventions.</Expects>


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
9 changes: 8 additions & 1 deletion tests/fsharp/tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,13 @@ module VersionTests =
[<Test>]
let ``member-selfidentifier-version4.7``() = singleTestBuildAndRunVersion "core/members/self-identifier/version47" FSC_BUILDONLY "preview"

[<Test>]
let ``indent-version4.6``() = singleTestBuildAndRunVersion "core/indent/version46" FSC_BUILDONLY "4.6"

[<Test>]
let ``indent-version4.7``() = singleTestBuildAndRunVersion "core/indent/version47" FSC_BUILDONLY "preview"


#if !FSHARP_SUITE_DRIVES_CORECLR_TESTS
module ToolsTests =

Expand All @@ -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"]
Expand Down
Loading