@@ -348,14 +348,28 @@ type PhasedDiagnostic =
348348 | BuildPhase.TypeCheck -> true
349349 | _ -> false
350350
351+ type PhasedDiagnosticWithSeverity =
352+ {
353+ PhasedDiagnostic: PhasedDiagnostic
354+ Severity: FSharpDiagnosticSeverity
355+ DefaultSeverity: FSharpDiagnosticSeverity
356+ }
357+
358+ static member Create ( phasedDiagnostic , severity ) =
359+ {
360+ PhasedDiagnostic = phasedDiagnostic
361+ Severity = severity
362+ DefaultSeverity = severity
363+ }
364+
351365[<AbstractClass>]
352366[<DebuggerDisplay( " {DebugDisplay()}" ) >]
353367type DiagnosticsLogger ( nameForDebugging : string ) =
354368 abstract ErrorCount: int
355369
356370 // The 'Impl' factoring enables a developer to place a breakpoint at the non-Impl
357371 // code just below and get a breakpoint for all error logger implementations.
358- abstract DiagnosticSink: diagnostic : PhasedDiagnostic * severity : FSharpDiagnosticSeverity -> unit
372+ abstract DiagnosticSink: diagnostic : PhasedDiagnosticWithSeverity -> unit
359373
360374 member x.CheckForErrors () = ( x.ErrorCount > 0 )
361375
@@ -367,14 +381,14 @@ type DiagnosticsLogger(nameForDebugging: string) =
367381
368382let DiscardErrorsLogger =
369383 { new DiagnosticsLogger( " DiscardErrorsLogger" ) with
370- member _.DiagnosticSink ( diagnostic , severity ) = ()
384+ member _.DiagnosticSink ( diagnostic ) = ()
371385 member _.ErrorCount = 0
372386 }
373387
374388let AssertFalseDiagnosticsLogger =
375389 { new DiagnosticsLogger( " AssertFalseDiagnosticsLogger" ) with
376390 // TODO: reenable these asserts in the compiler service
377- member _.DiagnosticSink ( diagnostic , severity ) = (* assert false; *) ()
391+ member _.DiagnosticSink ( diagnostic ) = (* assert false; *) ()
378392 member _.ErrorCount = (* assert false; *) 0
379393 }
380394
@@ -383,16 +397,19 @@ type CapturingDiagnosticsLogger(nm, ?eagerFormat) =
383397 let mutable errorCount = 0
384398 let diagnostics = ResizeArray()
385399
386- override _.DiagnosticSink ( diagnostic , severity ) =
400+ override _.DiagnosticSink ( diagnostic ) =
387401 let diagnostic =
388402 match eagerFormat with
389403 | None -> diagnostic
390- | Some f -> f diagnostic
404+ | Some f ->
405+ { diagnostic with
406+ PhasedDiagnostic = f diagnostic.PhasedDiagnostic
407+ }
391408
392- if severity = FSharpDiagnosticSeverity.Error then
409+ if diagnostic.Severity = FSharpDiagnosticSeverity.Error then
393410 errorCount <- errorCount + 1
394411
395- diagnostics.Add( diagnostic, severity )
412+ diagnostics.Add( diagnostic)
396413
397414 override _.ErrorCount = errorCount
398415
@@ -457,7 +474,14 @@ module DiagnosticsLoggerExtensions =
457474 | ReportedError _ ->
458475 PreserveStackTrace exn
459476 raise exn
460- | _ -> x.DiagnosticSink( PhasedDiagnostic.Create( exn, DiagnosticsThreadStatics.BuildPhase), severity)
477+ | _ ->
478+ let phasedDiagnostic =
479+ PhasedDiagnostic.Create( exn, DiagnosticsThreadStatics.BuildPhase)
480+
481+ let diagnosticWithSeverity =
482+ PhasedDiagnosticWithSeverity.Create( phasedDiagnostic, severity)
483+
484+ x.DiagnosticSink( diagnosticWithSeverity)
461485
462486 member x.ErrorR exn =
463487 x.EmitDiagnostic( exn, FSharpDiagnosticSeverity.Error)
@@ -472,8 +496,11 @@ module DiagnosticsLoggerExtensions =
472496 x.ErrorR exn
473497 raise ( ReportedError( Some exn))
474498
475- member x.SimulateError diagnostic =
476- x.DiagnosticSink( diagnostic, FSharpDiagnosticSeverity.Error)
499+ member x.SimulateError ( diagnostic ) =
500+ let diagnosticWithSeverity =
501+ PhasedDiagnosticWithSeverity.Create( diagnostic, FSharpDiagnosticSeverity.Error)
502+
503+ x.DiagnosticSink( diagnosticWithSeverity)
477504 raise ( ReportedError( Some diagnostic.Exception))
478505
479506 member x.ErrorRecovery ( exn : exn ) ( m : range ) =
@@ -580,17 +607,17 @@ let error exn =
580607 DiagnosticsThreadStatics.DiagnosticsLogger.Error exn
581608
582609/// Simulates an error. For test purposes only.
583- let simulateError ( diagnostic : PhasedDiagnostic ) =
584- DiagnosticsThreadStatics.DiagnosticsLogger.SimulateError diagnostic
610+ let simulateError diagnostic =
611+ DiagnosticsThreadStatics.DiagnosticsLogger.SimulateError( diagnostic)
585612
586- let diagnosticSink ( diagnostic , severity ) =
587- DiagnosticsThreadStatics.DiagnosticsLogger.DiagnosticSink( diagnostic, severity )
613+ let diagnosticSink diagnostic =
614+ DiagnosticsThreadStatics.DiagnosticsLogger.DiagnosticSink( diagnostic)
588615
589616let errorSink diagnostic =
590- diagnosticSink ( diagnostic, FSharpDiagnosticSeverity.Error)
617+ diagnosticSink ( PhasedDiagnosticWithSeverity.Create ( diagnostic, FSharpDiagnosticSeverity.Error) )
591618
592619let warnSink diagnostic =
593- diagnosticSink ( diagnostic, FSharpDiagnosticSeverity.Warning)
620+ diagnosticSink ( PhasedDiagnosticWithSeverity.Create ( diagnostic, FSharpDiagnosticSeverity.Warning) )
594621
595622let errorRecovery exn m =
596623 DiagnosticsThreadStatics.DiagnosticsLogger.ErrorRecovery exn m
@@ -623,7 +650,7 @@ let suppressErrorReporting f =
623650 try
624651 let diagnosticsLogger =
625652 { new DiagnosticsLogger( " suppressErrorReporting" ) with
626- member _.DiagnosticSink ( _phasedError , _isError ) = ()
653+ member _.DiagnosticSink ( _diagnosticWithSeverity ) = ()
627654 member _.ErrorCount = 0
628655 }
629656
0 commit comments