Skip to content

Commit

Permalink
Fix langversion with multiple projects (#7293)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom authored and TIHan committed Jul 30, 2019
1 parent d488458 commit 9c1a0d1
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 235 deletions.
1 change: 1 addition & 0 deletions src/fsharp/CompileOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ type TcConfig =
member copyFSharpCore: CopyFSharpCoreFlag
member shadowCopyReferences: bool
member useSdkRefs: bool
member langVersion: LanguageVersion

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

Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ type LanguageVersion (specifiedVersion) =
let label = if v = defaultVersion then " (Default)" else ""
yield sprintf "%M%s" v label
|]

/// Get the specified LanguageVersion
member __.SpecifiedVerson = specified
3 changes: 3 additions & 0 deletions src/fsharp/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ type LanguageVersion =

/// Get the list of valid options
member ValidOptions: string array

/// Get the specified LanguageVersion
member SpecifiedVerson: decimal
13 changes: 7 additions & 6 deletions src/fsharp/service/IncrementalBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ type TypeCheckAccumulator =


/// Global service state
type FrameworkImportsCacheKey = (*resolvedpath*)string list * string * (*TargetFrameworkDirectories*)string list* (*fsharpBinaries*)string
type FrameworkImportsCacheKey = (*resolvedpath*)string list * string * (*TargetFrameworkDirectories*)string list * (*fsharpBinaries*)string * (*langVersion*)decimal

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

match frameworkTcImportsCache.TryGet (ctok, key) with
match frameworkTcImportsCache.TryGet (ctok, key) with
| Some res -> return res
| None ->
let tcConfigP = TcConfigProvider.Constant tcConfig
Expand Down
173 changes: 173 additions & 0 deletions tests/fsharp/Compiler/Language/OpenStaticClasses.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests

open FSharp.Compiler.SourceCodeServices
open NUnit.Framework


(*
Tests in this file evaluate whether the language supports accessing functions on static classes using open
The feature was added in FSharp4.7, the test cases ensure that the original errors are reproduced when the langversion:4.6 is specified
*)

[<TestFixture>]
module OpenStaticClassesTests =

let baseModule = """
module Core_OpenStaticClasses
[<AbstractClass; Sealed>]
type MyMath() =
static member Min(a: double, b: double) = System.Math.Min(a, b)
static member Min(a: int, b: int) = System.Math.Min(a, b)
[<AbstractClass; Sealed; AutoOpen>]
type AutoOpenMyMath() =
static member AutoMin(a: double, b: double) = System.Math.Min(a, b)
static member AutoMin(a: int, b: int) = System.Math.Min(a, b)
[<AbstractClass; Sealed; RequireQualifiedAccess>]
type NotAllowedToOpen() =
static member QualifiedMin(a: double, b: double) = System.Math.Min(a, b)
static member QualifiedMin(a: int, b: int) = System.Math.Min(a, b)
"""

[<Test>]
let ``OpenStaticClassesTests - OpenSystemMathOnce - langversion:v4.6`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.6" |]
(baseModule + """
module OpenSystemMathOnce =
open System.Math
let x = Min(1.0, 2.0)""")
[|
(FSharpErrorSeverity.Error, 39, (22,28,22,32), "The namespace 'Math' is not defined.");
(FSharpErrorSeverity.Error, 39, (23,24,23,27), "The value or constructor 'Min' is not defined.")
|]

[<Test>]
let ``OpenStaticClassesTests - OpenSystemMathOnce - langversion:v4.7`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.7" |]
(baseModule + """
module OpenSystemMathOnce =
open System.Math
let x = Min(1.0, 2.0)""")
[| |]

[<Test>]
let ``OpenStaticClassesTests - OpenSystemMathTwice - langversion:v4.6`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.6" |]
(baseModule + """
module OpenSystemMathTwice =
open System.Math
let x = Min(1.0, 2.0)
open System.Math
let x2 = Min(2.0, 1.0)""")
[|
(FSharpErrorSeverity.Error, 39, (22,17,22,21), "The namespace 'Math' is not defined.");
(FSharpErrorSeverity.Error, 39, (23,13,23,16), "The value or constructor 'Min' is not defined.")
(FSharpErrorSeverity.Error, 39, (25,17,25,21), "The namespace 'Math' is not defined.");
(FSharpErrorSeverity.Error, 39, (26,14,26,17), "The value or constructor 'Min' is not defined.")
|]

[<Test>]
let ``OpenStaticClassesTests - OpenSystemMathTwice - langversion:v4.7`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.7" |]
(baseModule + """
module OpenSystemMathOnce =
open System.Math
let x = Min(1.0, 2.0)""")
[| |]

[<Test>]
let ``OpenStaticClassesTests - OpenMyMathOnce - langversion:v4.6`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.6" |]
(baseModule + """
module OpenMyMathOnce =
open MyMath
let x = Min(1.0, 2.0)
let x2 = Min(1, 2)""")
[|
(FSharpErrorSeverity.Error, 39, (22,10,22,16), "The namespace or module 'MyMath' is not defined.");
(FSharpErrorSeverity.Error, 39, (23,13,23,16), "The value or constructor 'Min' is not defined.")
(FSharpErrorSeverity.Error, 39, (24,14,24,17), "The value or constructor 'Min' is not defined.")
|]

[<Test>]
let ``OpenStaticClassesTests - OpenMyMathOnce - langversion:v4.7`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.7" |]
(baseModule + """
module OpenMyMathOnce =
open MyMath
let x = Min(1.0, 2.0)
let x2 = Min(1, 2)""")
[| |]

[<Test>]
let ``OpenStaticClassesTests - DontOpenAutoMath - langversion:v4.6`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.6" |]
(baseModule + """
module DontOpenAutoMath =
let x = AutoMin(1.0, 2.0)
let x2 = AutoMin(1, 2)""")
[|
(FSharpErrorSeverity.Error, 39, (22,13,22,20), "The value or constructor 'AutoMin' is not defined.");
(FSharpErrorSeverity.Error, 39, (23,14,23,21), "The value or constructor 'AutoMin' is not defined.")
|]

[<Test>]
let ``OpenStaticClassesTests - DontOpenAutoMath - langversion:v4.7`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.7" |]
(baseModule + """
module DontOpenAutoMath =
let x = AutoMin(1.0, 2.0)
let x2 = AutoMin(1, 2)""")
[| |]

[<Test>]
let ``OpenStaticClassesTests - OpenAutoMath - langversion:v4.6`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.6" |]
(baseModule + """
module OpenAutoMath =
open AutoOpenMyMath
//open NotAllowedToOpen
let x = AutoMin(1.0, 2.0)
let x2 = AutoMin(1, 2)""")
[|
(FSharpErrorSeverity.Error, 39, (21,10,21,24), "The namespace or module 'AutoOpenMyMath' is not defined.");
(FSharpErrorSeverity.Error, 39, (24,13,24,20), "The value or constructor 'AutoMin' is not defined.")
(FSharpErrorSeverity.Error, 39, (25,14,25,21), "The value or constructor 'AutoMin' is not defined.")
|]

[<Test>]
let ``OpenStaticClassesTests - OpenAutoMath - langversion:v4.7`` () =
CompilerAssert.TypeCheckWithErrorsAndOptions
[| "--langversion:4.7" |]
(baseModule + """
module OpenAutoMath =
open AutoOpenMyMath
//open NotAllowedToOpen
let x = AutoMin(1.0, 2.0)
let x2 = AutoMin(1, 2)""")
[| |]
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="Compiler\ErrorMessages\WarnExpressionTests.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\AnonRecordTests.fs" />
<Compile Include="Compiler\Language\OpenStaticClasses.fs" />
<Compile Include="Compiler\Language\SpanOptimizationTests.fs" />
<Compile Include="Compiler\Language\SpanTests.fs" />
<Compile Include="Compiler\Language\StringConcatOptimizationTests.fs" />
Expand Down
39 changes: 0 additions & 39 deletions tests/fsharp/core/longnames/version46/test.bsl

This file was deleted.

84 changes: 0 additions & 84 deletions tests/fsharp/core/longnames/version46/test.fs

This file was deleted.

Loading

0 comments on commit 9c1a0d1

Please sign in to comment.