Skip to content

Commit 9c1a0d1

Browse files
KevinRansomTIHan
authored andcommitted
Fix langversion with multiple projects (#7293)
1 parent d488458 commit 9c1a0d1

10 files changed

Lines changed: 188 additions & 235 deletions

File tree

src/fsharp/CompileOps.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ type TcConfig =
552552
member copyFSharpCore: CopyFSharpCoreFlag
553553
member shadowCopyReferences: bool
554554
member useSdkRefs: bool
555+
member langVersion: LanguageVersion
555556

556557
static member Create: TcConfigBuilder * validate: bool -> TcConfig
557558

src/fsharp/LanguageFeatures.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ type LanguageVersion (specifiedVersion) =
9393
let label = if v = defaultVersion then " (Default)" else ""
9494
yield sprintf "%M%s" v label
9595
|]
96+
97+
/// Get the specified LanguageVersion
98+
member __.SpecifiedVerson = specified

src/fsharp/LanguageFeatures.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ type LanguageVersion =
3434

3535
/// Get the list of valid options
3636
member ValidOptions: string array
37+
38+
/// Get the specified LanguageVersion
39+
member SpecifiedVerson: decimal

src/fsharp/service/IncrementalBuild.fs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ type TypeCheckAccumulator =
10521052

10531053

10541054
/// Global service state
1055-
type FrameworkImportsCacheKey = (*resolvedpath*)string list * string * (*TargetFrameworkDirectories*)string list* (*fsharpBinaries*)string
1055+
type FrameworkImportsCacheKey = (*resolvedpath*)string list * string * (*TargetFrameworkDirectories*)string list * (*fsharpBinaries*)string * (*langVersion*)decimal
10561056

10571057
/// Represents a cache of 'framework' references that can be shared betweeen multiple incremental builds
10581058
type FrameworkImportsCache(keepStrongly) =
@@ -1083,12 +1083,13 @@ type FrameworkImportsCache(keepStrongly) =
10831083
// The data elements in this key are very important. There should be nothing else in the TcConfig that logically affects
10841084
// the import of a set of framework DLLs into F# CCUs. That is, the F# CCUs that result from a set of DLLs (including
10851085
// FSharp.Core.dll and mscorlib.dll) must be logically invariant of all the other compiler configuration parameters.
1086-
let key = (frameworkDLLsKey,
1087-
tcConfig.primaryAssembly.Name,
1088-
tcConfig.GetTargetFrameworkDirectories(),
1089-
tcConfig.fsharpBinariesDir)
1086+
let key = (frameworkDLLsKey,
1087+
tcConfig.primaryAssembly.Name,
1088+
tcConfig.GetTargetFrameworkDirectories(),
1089+
tcConfig.fsharpBinariesDir,
1090+
tcConfig.langVersion.SpecifiedVerson)
10901091

1091-
match frameworkTcImportsCache.TryGet (ctok, key) with
1092+
match frameworkTcImportsCache.TryGet (ctok, key) with
10921093
| Some res -> return res
10931094
| None ->
10941095
let tcConfigP = TcConfigProvider.Constant tcConfig
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace FSharp.Compiler.UnitTests
4+
5+
open FSharp.Compiler.SourceCodeServices
6+
open NUnit.Framework
7+
8+
9+
(*
10+
Tests in this file evaluate whether the language supports accessing functions on static classes using open
11+
The feature was added in FSharp4.7, the test cases ensure that the original errors are reproduced when the langversion:4.6 is specified
12+
*)
13+
14+
[<TestFixture>]
15+
module OpenStaticClassesTests =
16+
17+
let baseModule = """
18+
module Core_OpenStaticClasses
19+
20+
[<AbstractClass; Sealed>]
21+
type MyMath() =
22+
static member Min(a: double, b: double) = System.Math.Min(a, b)
23+
static member Min(a: int, b: int) = System.Math.Min(a, b)
24+
25+
[<AbstractClass; Sealed; AutoOpen>]
26+
type AutoOpenMyMath() =
27+
static member AutoMin(a: double, b: double) = System.Math.Min(a, b)
28+
static member AutoMin(a: int, b: int) = System.Math.Min(a, b)
29+
30+
[<AbstractClass; Sealed; RequireQualifiedAccess>]
31+
type NotAllowedToOpen() =
32+
static member QualifiedMin(a: double, b: double) = System.Math.Min(a, b)
33+
static member QualifiedMin(a: int, b: int) = System.Math.Min(a, b)
34+
35+
"""
36+
37+
[<Test>]
38+
let ``OpenStaticClassesTests - OpenSystemMathOnce - langversion:v4.6`` () =
39+
CompilerAssert.TypeCheckWithErrorsAndOptions
40+
[| "--langversion:4.6" |]
41+
(baseModule + """
42+
module OpenSystemMathOnce =
43+
44+
open System.Math
45+
let x = Min(1.0, 2.0)""")
46+
[|
47+
(FSharpErrorSeverity.Error, 39, (22,28,22,32), "The namespace 'Math' is not defined.");
48+
(FSharpErrorSeverity.Error, 39, (23,24,23,27), "The value or constructor 'Min' is not defined.")
49+
|]
50+
51+
[<Test>]
52+
let ``OpenStaticClassesTests - OpenSystemMathOnce - langversion:v4.7`` () =
53+
CompilerAssert.TypeCheckWithErrorsAndOptions
54+
[| "--langversion:4.7" |]
55+
(baseModule + """
56+
module OpenSystemMathOnce =
57+
58+
open System.Math
59+
let x = Min(1.0, 2.0)""")
60+
[| |]
61+
62+
[<Test>]
63+
let ``OpenStaticClassesTests - OpenSystemMathTwice - langversion:v4.6`` () =
64+
CompilerAssert.TypeCheckWithErrorsAndOptions
65+
[| "--langversion:4.6" |]
66+
(baseModule + """
67+
module OpenSystemMathTwice =
68+
69+
open System.Math
70+
let x = Min(1.0, 2.0)
71+
72+
open System.Math
73+
let x2 = Min(2.0, 1.0)""")
74+
[|
75+
(FSharpErrorSeverity.Error, 39, (22,17,22,21), "The namespace 'Math' is not defined.");
76+
(FSharpErrorSeverity.Error, 39, (23,13,23,16), "The value or constructor 'Min' is not defined.")
77+
(FSharpErrorSeverity.Error, 39, (25,17,25,21), "The namespace 'Math' is not defined.");
78+
(FSharpErrorSeverity.Error, 39, (26,14,26,17), "The value or constructor 'Min' is not defined.")
79+
|]
80+
81+
[<Test>]
82+
let ``OpenStaticClassesTests - OpenSystemMathTwice - langversion:v4.7`` () =
83+
CompilerAssert.TypeCheckWithErrorsAndOptions
84+
[| "--langversion:4.7" |]
85+
(baseModule + """
86+
module OpenSystemMathOnce =
87+
88+
open System.Math
89+
let x = Min(1.0, 2.0)""")
90+
[| |]
91+
92+
[<Test>]
93+
let ``OpenStaticClassesTests - OpenMyMathOnce - langversion:v4.6`` () =
94+
CompilerAssert.TypeCheckWithErrorsAndOptions
95+
[| "--langversion:4.6" |]
96+
(baseModule + """
97+
module OpenMyMathOnce =
98+
99+
open MyMath
100+
let x = Min(1.0, 2.0)
101+
let x2 = Min(1, 2)""")
102+
[|
103+
(FSharpErrorSeverity.Error, 39, (22,10,22,16), "The namespace or module 'MyMath' is not defined.");
104+
(FSharpErrorSeverity.Error, 39, (23,13,23,16), "The value or constructor 'Min' is not defined.")
105+
(FSharpErrorSeverity.Error, 39, (24,14,24,17), "The value or constructor 'Min' is not defined.")
106+
|]
107+
108+
[<Test>]
109+
let ``OpenStaticClassesTests - OpenMyMathOnce - langversion:v4.7`` () =
110+
CompilerAssert.TypeCheckWithErrorsAndOptions
111+
[| "--langversion:4.7" |]
112+
(baseModule + """
113+
module OpenMyMathOnce =
114+
115+
open MyMath
116+
let x = Min(1.0, 2.0)
117+
let x2 = Min(1, 2)""")
118+
[| |]
119+
120+
[<Test>]
121+
let ``OpenStaticClassesTests - DontOpenAutoMath - langversion:v4.6`` () =
122+
CompilerAssert.TypeCheckWithErrorsAndOptions
123+
[| "--langversion:4.6" |]
124+
(baseModule + """
125+
module DontOpenAutoMath =
126+
127+
let x = AutoMin(1.0, 2.0)
128+
let x2 = AutoMin(1, 2)""")
129+
[|
130+
(FSharpErrorSeverity.Error, 39, (22,13,22,20), "The value or constructor 'AutoMin' is not defined.");
131+
(FSharpErrorSeverity.Error, 39, (23,14,23,21), "The value or constructor 'AutoMin' is not defined.")
132+
|]
133+
134+
[<Test>]
135+
let ``OpenStaticClassesTests - DontOpenAutoMath - langversion:v4.7`` () =
136+
CompilerAssert.TypeCheckWithErrorsAndOptions
137+
[| "--langversion:4.7" |]
138+
(baseModule + """
139+
module DontOpenAutoMath =
140+
141+
let x = AutoMin(1.0, 2.0)
142+
let x2 = AutoMin(1, 2)""")
143+
[| |]
144+
145+
[<Test>]
146+
let ``OpenStaticClassesTests - OpenAutoMath - langversion:v4.6`` () =
147+
CompilerAssert.TypeCheckWithErrorsAndOptions
148+
[| "--langversion:4.6" |]
149+
(baseModule + """
150+
module OpenAutoMath =
151+
open AutoOpenMyMath
152+
//open NotAllowedToOpen
153+
154+
let x = AutoMin(1.0, 2.0)
155+
let x2 = AutoMin(1, 2)""")
156+
[|
157+
(FSharpErrorSeverity.Error, 39, (21,10,21,24), "The namespace or module 'AutoOpenMyMath' is not defined.");
158+
(FSharpErrorSeverity.Error, 39, (24,13,24,20), "The value or constructor 'AutoMin' is not defined.")
159+
(FSharpErrorSeverity.Error, 39, (25,14,25,21), "The value or constructor 'AutoMin' is not defined.")
160+
|]
161+
162+
[<Test>]
163+
let ``OpenStaticClassesTests - OpenAutoMath - langversion:v4.7`` () =
164+
CompilerAssert.TypeCheckWithErrorsAndOptions
165+
[| "--langversion:4.7" |]
166+
(baseModule + """
167+
module OpenAutoMath =
168+
open AutoOpenMyMath
169+
//open NotAllowedToOpen
170+
171+
let x = AutoMin(1.0, 2.0)
172+
let x2 = AutoMin(1, 2)""")
173+
[| |]

tests/fsharp/FSharpSuite.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="Compiler\ErrorMessages\WarnExpressionTests.fs" />
4848
<Compile Include="Compiler\SourceTextTests.fs" />
4949
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
50+
<Compile Include="Compiler\Language\OpenStaticClasses.fs" />
5051
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />
5152
<Compile Include="Compiler\Language\SpanTests.fs" />
5253
<Compile Include="Compiler\Language\StringConcatOptimizationTests.fs" />

tests/fsharp/core/longnames/version46/test.bsl

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/fsharp/core/longnames/version46/test.fs

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)