Skip to content
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
8 changes: 5 additions & 3 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,8 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i

let dummyScriptFileName = "input.fsx"

let eagerFormat (diag : PhasedDiagnostic) = diag.EagerlyFormatCore true

interface IDisposable with
member _.Dispose() =
(tcImports :> IDisposable).Dispose()
Expand Down Expand Up @@ -3639,7 +3641,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
let ctok = AssumeCompilationThreadWithoutEvidence()

let errorOptions = TcConfig.Create(tcConfigB,validate = false).diagnosticsOptions
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions)
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat)
fsiInteractionProcessor.EvalExpression(ctok, code, dummyScriptFileName, diagnosticsLogger)
|> commitResultNonThrowing errorOptions dummyScriptFileName diagnosticsLogger

Expand All @@ -3661,7 +3663,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
let cancellationToken = defaultArg cancellationToken CancellationToken.None

let errorOptions = TcConfig.Create(tcConfigB,validate = false).diagnosticsOptions
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions)
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat)
fsiInteractionProcessor.EvalInteraction(ctok, code, dummyScriptFileName, diagnosticsLogger, cancellationToken)
|> commitResultNonThrowing errorOptions "input.fsx" diagnosticsLogger

Expand All @@ -3682,7 +3684,7 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
let ctok = AssumeCompilationThreadWithoutEvidence()

let errorOptions = TcConfig.Create(tcConfigB, validate = false).diagnosticsOptions
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions)
let diagnosticsLogger = CompilationDiagnosticLogger("EvalInteraction", errorOptions, eagerFormat)
fsiInteractionProcessor.EvalScript(ctok, filePath, diagnosticsLogger)
|> commitResultNonThrowing errorOptions filePath diagnosticsLogger
|> function Choice1Of2 _, errs -> Choice1Of2 (), errs | Choice2Of2 exn, errs -> Choice2Of2 exn, errs
Expand Down
9 changes: 7 additions & 2 deletions src/Compiler/Symbols/FSharpDiagnostic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,26 @@ type DiagnosticsScope() =
| None -> err ""

/// A diagnostics logger that capture diagnostics, filtering them according to warning levels etc.
type internal CompilationDiagnosticLogger (debugName: string, options: FSharpDiagnosticOptions) =
type internal CompilationDiagnosticLogger (debugName: string, options: FSharpDiagnosticOptions, ?preprocess: (PhasedDiagnostic -> PhasedDiagnostic)) =
inherit DiagnosticsLogger("CompilationDiagnosticLogger("+debugName+")")

let mutable errorCount = 0
let diagnostics = ResizeArray<_>()

override _.DiagnosticSink(diagnostic, severity) =
let diagnostic =
match preprocess with
| Some f -> f diagnostic
| None -> diagnostic

if diagnostic.ReportAsError (options, severity) then
diagnostics.Add(diagnostic, FSharpDiagnosticSeverity.Error)
errorCount <- errorCount + 1
elif diagnostic.ReportAsWarning (options, severity) then
diagnostics.Add(diagnostic, FSharpDiagnosticSeverity.Warning)
elif diagnostic.ReportAsInfo (options, severity) then
diagnostics.Add(diagnostic, severity)

override _.ErrorCount = errorCount

member _.GetDiagnostics() = diagnostics.ToArray()
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/Symbols/FSharpDiagnostic.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ type internal CompilationDiagnosticLogger =
inherit DiagnosticsLogger

/// Create the diagnostics logger
new: debugName: string * options: FSharpDiagnosticOptions -> CompilationDiagnosticLogger
new:
debugName: string * options: FSharpDiagnosticOptions * ?preprocess: (PhasedDiagnostic -> PhasedDiagnostic) ->
CompilationDiagnosticLogger

/// Get the captured diagnostics
member GetDiagnostics: unit -> (PhasedDiagnostic * FSharpDiagnosticSeverity)[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ open Xunit

type InteractiveTests() =

[<Fact>]
member _.``ValueRestriction error message should not have type variables fully solved``() =
use script = new FSharpScript()
let code = "id id"
let _, errors = script.Eval(code)
Assert.Equal(1, errors.Length)
let msg = errors[0].Message
Assert.Matches("'_\\w+ -> '_\\w+", msg)

[<Fact>]
member _.``Eval object value``() =
use script = new FSharpScript()
Expand Down