22
33module public Microsoft.FSharp.Compiler.ErrorLogger
44
5- open Internal.Utilities
65open Microsoft.FSharp .Compiler
7- open Microsoft.FSharp .Compiler .AbstractIL .Diagnostics
8- open Microsoft.FSharp .Compiler .AbstractIL .Internal .Library
9- open Microsoft.FSharp .Compiler .Lib
106open Microsoft.FSharp .Compiler .Range
117open System
128
@@ -109,23 +105,23 @@ exception ErrorWithSuggestions of (int * string) * range * string * Suggestions
109105let inline protectAssemblyExploration dflt f =
110106 try
111107 f()
112- with
113- | UnresolvedPathReferenceNoRange _ -> dflt
114- | _ -> reraise()
108+ with
109+ | UnresolvedPathReferenceNoRange _ -> dflt
110+ | _ -> reraise()
115111
116112let inline protectAssemblyExplorationF dflt f =
117113 try
118114 f()
119- with
120- | UnresolvedPathReferenceNoRange ( asmName, path) -> dflt( asmName, path)
121- | _ -> reraise()
115+ with
116+ | UnresolvedPathReferenceNoRange ( asmName, path) -> dflt( asmName, path)
117+ | _ -> reraise()
122118
123119let inline protectAssemblyExplorationNoReraise dflt1 dflt2 f =
124120 try
125121 f()
126- with
127- | UnresolvedPathReferenceNoRange _ -> dflt1
128- | _ -> dflt2
122+ with
123+ | UnresolvedPathReferenceNoRange _ -> dflt1
124+ | _ -> dflt2
129125
130126// Attach a range if this is a range dual exception.
131127let rec AttachRange m ( exn : exn ) =
@@ -150,20 +146,22 @@ type Exiter =
150146
151147let QuitProcessExiter =
152148 { new Exiter with
153- member x .Exit( n ) =
149+ member __ .Exit( n ) =
154150 try
155151 System.Environment.Exit( n)
156152 with _ ->
157153 ()
158- failwithf " %s " <| FSComp.SR.elSysEnvExitDidntExit() }
154+ FSComp.SR.elSysEnvExitDidntExit()
155+ |> failwith }
159156
160157/// Closed enumeration of build phases.
158+ [<RequireQualifiedAccess>]
161159type BuildPhase =
162160 | DefaultPhase
163161 | Compile
164162 | Parameter | Parse | TypeCheck
165163 | CodeGen
166- | Optimize | IlxGen | IlGen | Output
164+ | Optimize | IlxGen | IlGen | Output
167165 | Interactive // An error seen during interactive execution
168166
169167/// Literal build phase subcategory strings.
@@ -212,17 +210,17 @@ type PhasedDiagnostic =
212210 ///
213211 member pe.Subcategory () =
214212 match pe.Phase with
215- | DefaultPhase -> BuildPhaseSubcategory.DefaultPhase
216- | Compile -> BuildPhaseSubcategory.Compile
217- | Parameter -> BuildPhaseSubcategory.Parameter
218- | Parse -> BuildPhaseSubcategory.Parse
219- | TypeCheck -> BuildPhaseSubcategory.TypeCheck
220- | CodeGen -> BuildPhaseSubcategory.CodeGen
221- | Optimize -> BuildPhaseSubcategory.Optimize
222- | IlxGen -> BuildPhaseSubcategory.IlxGen
223- | IlGen -> BuildPhaseSubcategory.IlGen
224- | Output -> BuildPhaseSubcategory.Output
225- | Interactive -> BuildPhaseSubcategory.Interactive
213+ | BuildPhase. DefaultPhase -> BuildPhaseSubcategory.DefaultPhase
214+ | BuildPhase. Compile -> BuildPhaseSubcategory.Compile
215+ | BuildPhase. Parameter -> BuildPhaseSubcategory.Parameter
216+ | BuildPhase. Parse -> BuildPhaseSubcategory.Parse
217+ | BuildPhase. TypeCheck -> BuildPhaseSubcategory.TypeCheck
218+ | BuildPhase. CodeGen -> BuildPhaseSubcategory.CodeGen
219+ | BuildPhase. Optimize -> BuildPhaseSubcategory.Optimize
220+ | BuildPhase. IlxGen -> BuildPhaseSubcategory.IlxGen
221+ | BuildPhase. IlGen -> BuildPhaseSubcategory.IlGen
222+ | BuildPhase. Output -> BuildPhaseSubcategory.Output
223+ | BuildPhase. Interactive -> BuildPhaseSubcategory.Interactive
226224
227225 /// Return true if the textual phase given is from the compile part of the build process.
228226 /// This set needs to be equal to the set of subcategories that the language service can produce.
@@ -256,7 +254,7 @@ type PhasedDiagnostic =
256254 member pe.IsPhaseInCompile () =
257255 let isPhaseInCompile =
258256 match pe.Phase with
259- | Compile | Parameter | Parse | TypeCheck -> true
257+ | BuildPhase. Compile | BuildPhase. Parameter | BuildPhase. Parse | BuildPhase. TypeCheck -> true
260258 | _ -> false
261259 // Sanity check ensures that Phase matches Subcategory
262260#if DEBUG
@@ -274,7 +272,7 @@ type ErrorLogger(nameForDebugging:string) =
274272 // The 'Impl' factoring enables a developer to place a breakpoint at the non-Impl
275273 // code just below and get a breakpoint for all error logger implementations.
276274 abstract DiagnosticSink: phasedError : PhasedDiagnostic * isError : bool -> unit
277- member this .DebugDisplay() = sprintf " ErrorLogger(%s )" nameForDebugging
275+ member __ .DebugDisplay() = sprintf " ErrorLogger(%s )" nameForDebugging
278276
279277let DiscardErrorsLogger =
280278 { new ErrorLogger( " DiscardErrorsLogger" ) with
@@ -337,7 +335,7 @@ module ErrorLoggerExtensions =
337335 try
338336 let preserveStackTrace = typeof< System.Exception>. GetMethod( " InternalPreserveStackTrace" , BindingFlags.Instance ||| BindingFlags.NonPublic)
339337 preserveStackTrace.Invoke( exn, null ) |> ignore
340- with e ->
338+ with _ ->
341339 // This is probably only the mono case.
342340 System.Diagnostics.Debug.Assert( false , " Could not preserve stack trace for watson exception." )
343341 ()
@@ -411,7 +409,7 @@ module ErrorLoggerExtensions =
411409 x.ErrorR ( AttachRange m exn) // may raise exceptions, e.g. an fsi error sink raises StopProcessing.
412410 ReraiseIfWatsonable( exn)
413411 with
414- | ReportedError _ | WrappedError( ReportedError _, _) -> ()
412+ | ReportedError _ | WrappedError( ReportedError _, _) -> ()
415413
416414 member x.StopProcessingRecovery ( exn : exn ) ( m : range ) =
417415 // Do standard error recovery.
@@ -421,10 +419,11 @@ module ErrorLoggerExtensions =
421419 match exn with
422420 | StopProcessing | WrappedError( StopProcessing, _) -> () // suppress, so skip error recovery.
423421 | _ ->
424- try x.ErrorRecovery exn m
422+ try
423+ x.ErrorRecovery exn m
425424 with
426- | StopProcessing | WrappedError( StopProcessing, _) -> () // catch, e.g. raised by DiagnosticSink.
427- | ReportedError _ | WrappedError( ReportedError _, _) -> () // catch, but not expected unless ErrorRecovery is changed.
425+ | StopProcessing | WrappedError( StopProcessing, _) -> () // catch, e.g. raised by DiagnosticSink.
426+ | ReportedError _ | WrappedError( ReportedError _, _) -> () // catch, but not expected unless ErrorRecovery is changed.
428427
429428 member x.ErrorRecoveryNoRange ( exn : exn ) =
430429 x.ErrorRecovery exn range0
@@ -445,13 +444,13 @@ let PushErrorLoggerPhaseUntilUnwind(errorLoggerTransformer : ErrorLogger -> #Err
445444 let newInstalled = ref true
446445 let newIsInstalled () = if ! newInstalled then () else ( assert false ; (); (* failwith "error logger used after unwind"*) ) // REVIEW: ok to throw?
447446 let chkErrorLogger = { new ErrorLogger( " PushErrorLoggerPhaseUntilUnwind" ) with
448- member x .DiagnosticSink( phasedError , isError ) = newIsInstalled(); newErrorLogger.DiagnosticSink( phasedError, isError)
449- member x .ErrorCount = newIsInstalled(); newErrorLogger.ErrorCount }
447+ member __ .DiagnosticSink( phasedError , isError ) = newIsInstalled(); newErrorLogger.DiagnosticSink( phasedError, isError)
448+ member __ .ErrorCount = newIsInstalled(); newErrorLogger.ErrorCount }
450449
451450 CompileThreadStatic.ErrorLogger <- chkErrorLogger
452451
453452 { new System.IDisposable with
454- member x .Dispose() =
453+ member __ .Dispose() =
455454 CompileThreadStatic.ErrorLogger <- oldErrorLogger
456455 newInstalled := false }
457456
@@ -461,13 +460,13 @@ let SetThreadErrorLoggerNoUnwind(errorLogger) = CompileThreadStatic.ErrorLog
461460// Global functions are still used by parser and TAST ops.
462461
463462/// Raises an exception with error recovery and returns unit.
464- let errorR exn = CompileThreadStatic.ErrorLogger.ErrorR exn
463+ let errorR exn = CompileThreadStatic.ErrorLogger.ErrorR exn
465464
466465/// Raises a warning with error recovery and returns unit.
467466let warning exn = CompileThreadStatic.ErrorLogger.Warning exn
468467
469468/// Raises a special exception and returns 'T - can be caught later at an errorRecovery point.
470- let error exn = CompileThreadStatic.ErrorLogger.Error exn
469+ let error exn = CompileThreadStatic.ErrorLogger.Error exn
471470
472471/// Simulates an error. For test purposes only.
473472let simulateError ( p : PhasedDiagnostic ) = CompileThreadStatic.ErrorLogger.SimulateError p
@@ -497,8 +496,8 @@ let suppressErrorReporting f =
497496 try
498497 let errorLogger =
499498 { new ErrorLogger( " suppressErrorReporting" ) with
500- member x .DiagnosticSink( _phasedError , _isError ) = ()
501- member x .ErrorCount = 0 }
499+ member __ .DiagnosticSink( _phasedError , _isError ) = ()
500+ member __ .ErrorCount = 0 }
502501 SetThreadErrorLoggerNoUnwind( errorLogger)
503502 f()
504503 finally
0 commit comments