Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<Compile Include="Signatures\TypeTests.fs" />
<Compile Include="Signatures\SigGenerationRoundTripTests.fs" />
<Compile Include="Signatures\NestedTypeTests.fs" />
<Compile Include="Signatures\MissingDiagnostic.fs" />
<Compile Include="StaticLinking\StaticLinking.fs" />
<Compile Include="FSharpChecker\CommonWorkflows.fs" />
<Compile Include="FSharpChecker\SymbolUse.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module FSharp.Compiler.ComponentTests.Signatures.MissingDiagnostic

open Xunit
open FSharp.Test
open FSharp.Test.Compiler

let implementation = """
module Foo

let a (b: int) : int = 'x'
"""

let signature = """
module Foo

val a: b: int -> int
"""

[<Fact>]
let ``Compile gives errors`` () =
Fsi signature
|> withAdditionalSourceFile (FsSource implementation)
|> compile
|> shouldFail
|> withSingleDiagnostic (Error 1, Line 4, Col 24, Line 4,Col 27, "This expression was expected to have type
'int'
but here has type
'char' ")

[<Fact>]
let ``Type check project with signature file doesn't get the diagnostic`` () =
Fsi signature
|> withAdditionalSourceFile (FsSource implementation)
|> typecheckProject false
|> fun projectResults ->
projectResults.Diagnostics |> ignore
Assert.False (projectResults.Diagnostics |> Array.isEmpty)

[<Fact>]
let ``Type check project without signature file does get the diagnostic`` () =
Fs implementation
|> typecheckProject false
|> fun projectResults ->
projectResults.Diagnostics |> ignore
Assert.False (projectResults.Diagnostics |> Array.isEmpty)

[<Fact>]
let ``Enabling enablePartialTypeChecking = true doesn't change the problem`` () =
Fsi signature
|> withAdditionalSourceFile (FsSource implementation)
|> typecheckProject true
|> fun projectResults ->
projectResults.Diagnostics |> ignore
Assert.False (projectResults.Diagnostics |> Array.isEmpty)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let private getGenericParametersNamesFor
(additionalFile: SourceCodeFileKind)
: string array =
let typeCheckResult =
cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject
cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject false

assert (Array.isEmpty typeCheckResult.Diagnostics)

Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ module rec Compiler =
CompilerAssert.TypeCheck(options, fileName, source)
| _ -> failwith "Typecheck only supports F#"

let typecheckProject (cUnit: CompilationUnit) : FSharp.Compiler.CodeAnalysis.FSharpCheckProjectResults =
let typecheckProject enablePartialTypeChecking (cUnit: CompilationUnit) : FSharp.Compiler.CodeAnalysis.FSharpCheckProjectResults =
match cUnit with
| FS fsSource ->
let options = fsSource.Options |> Array.ofList
Expand All @@ -935,7 +935,7 @@ module rec Compiler =
|> async.Return

let sourceFiles = Array.map fst sourceFiles
CompilerAssert.TypeCheckProject(options, sourceFiles, getSourceText)
CompilerAssert.TypeCheckProject(options, sourceFiles, getSourceText, enablePartialTypeChecking)
| _ -> failwith "Typecheck only supports F#"

let run (result: CompilationResult) : CompilationResult =
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Test.Utilities/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ Updated automatically, please check diffs in your pull request, changes must be
static member TypeCheckSingleError (source: string) (expectedSeverity: FSharpDiagnosticSeverity) (expectedErrorNumber: int) (expectedErrorRange: int * int * int * int) (expectedErrorMsg: string) =
CompilerAssert.TypeCheckWithErrors source [| expectedSeverity, expectedErrorNumber, expectedErrorRange, expectedErrorMsg |]

static member TypeCheckProject(options: string array, sourceFiles: string array, getSourceText) : FSharpCheckProjectResults =
let checker = FSharpChecker.Create(documentSource = DocumentSource.Custom getSourceText)
static member TypeCheckProject(options: string array, sourceFiles: string array, getSourceText, enablePartialTypeChecking) : FSharpCheckProjectResults =
let checker = FSharpChecker.Create(documentSource = DocumentSource.Custom getSourceText, enablePartialTypeChecking = enablePartialTypeChecking)
let defaultOptions = defaultProjectOptions TargetFramework.Current
let projectOptions = { defaultOptions with OtherOptions = Array.append options defaultOptions.OtherOptions; SourceFiles = sourceFiles }

Expand Down