Skip to content

Commit ce61954

Browse files
authored
Cleanup extended giagnostic data (#18854)
1 parent dc44561 commit ce61954

File tree

2 files changed

+88
-90
lines changed

2 files changed

+88
-90
lines changed

src/Compiler/Symbols/FSharpDiagnostic.fs

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace FSharp.Compiler.Diagnostics
99

1010
open System
1111

12-
open FSharp.Compiler.AttributeChecking
1312
open FSharp.Compiler.CheckExpressions
1413
open FSharp.Compiler.ConstraintSolver
1514
open FSharp.Compiler.SignatureConformance
@@ -26,11 +25,10 @@ open FSharp.Compiler.CompilerDiagnostics
2625
open FSharp.Compiler.Diagnostics
2726
open FSharp.Compiler.DiagnosticsLogger
2827
open FSharp.Compiler.Text
29-
open FSharp.Compiler.Text.Position
3028
open FSharp.Compiler.Text.Range
3129

3230
module ExtendedData =
33-
[<RequireQualifiedAccess; Experimental("This FCS API is experimental and subject to change.")>]
31+
[<RequireQualifiedAccess>]
3432
type DiagnosticContextInfo =
3533
| NoContext
3634
| IfExpression
@@ -46,7 +44,7 @@ module ExtendedData =
4644
| FollowingPatternMatchClause
4745
| PatternMatchGuard
4846
| SequenceExpression
49-
with
47+
5048
static member From(contextInfo: ContextInfo) =
5149
match contextInfo with
5250
| ContextInfo.NoContext -> NoContext
@@ -64,110 +62,83 @@ module ExtendedData =
6462
| ContextInfo.PatternMatchGuard _ -> PatternMatchGuard
6563
| ContextInfo.SequenceExpression _ -> SequenceExpression
6664

67-
[<Interface; Experimental("This FCS API is experimental and subject to change.")>]
68-
type IFSharpDiagnosticExtendedData = interface end
65+
type IFSharpDiagnosticExtendedData =
66+
interface end
6967

70-
/// Additional data for diagnostics about obsolete attributes.
71-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
72-
type ObsoleteDiagnosticExtendedData
73-
internal (diagnosticId: string option, urlFormat: string option) =
68+
type ObsoleteDiagnosticExtendedData internal (diagnosticId: string option, urlFormat: string option) =
7469
interface IFSharpDiagnosticExtendedData
75-
/// Represents the DiagnosticId of the diagnostic
76-
member this.DiagnosticId: string option = diagnosticId
7770

78-
/// Represents the URL format of the diagnostic
71+
member this.DiagnosticId: string option = diagnosticId
7972
member this.UrlFormat: string option = urlFormat
8073

81-
/// Additional data for diagnostics about experimental attributes.
82-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
83-
type ExperimentalExtendedData
84-
internal (diagnosticId: string option, urlFormat: string option) =
74+
type ExperimentalExtendedData internal (diagnosticId: string option, urlFormat: string option) =
8575
interface IFSharpDiagnosticExtendedData
86-
/// Represents the DiagnosticId of the diagnostic
87-
member this.DiagnosticId: string option = diagnosticId
8876

89-
/// Represents the URL format of the diagnostic
77+
member this.DiagnosticId: string option = diagnosticId
9078
member this.UrlFormat: string option = urlFormat
9179

92-
[<Experimental("This FCS API is experimental and subject to change.")>]
93-
type TypeMismatchDiagnosticExtendedData
94-
internal (symbolEnv: SymbolEnv, dispEnv: DisplayEnv, expectedType: TType, actualType: TType, context: DiagnosticContextInfo) =
80+
type TypeMismatchDiagnosticExtendedData internal (symbolEnv: SymbolEnv, dispEnv: DisplayEnv, expectedType: TType, actualType: TType,
81+
context: DiagnosticContextInfo) =
9582
interface IFSharpDiagnosticExtendedData
9683

9784
member x.ExpectedType = FSharpType(symbolEnv, expectedType)
9885
member x.ActualType = FSharpType(symbolEnv, actualType)
9986
member x.ContextInfo = context
10087
member x.DisplayContext = FSharpDisplayContext(fun _ -> dispEnv)
10188

102-
[<Experimental("This FCS API is experimental and subject to change.")>]
103-
type ExpressionIsAFunctionExtendedData
104-
internal (symbolEnv: SymbolEnv, actualType: TType) =
89+
type ExpressionIsAFunctionExtendedData internal (symbolEnv: SymbolEnv, actualType: TType) =
10590
interface IFSharpDiagnosticExtendedData
10691

10792
member x.ActualType = FSharpType(symbolEnv, actualType)
10893

109-
[<Experimental("This FCS API is experimental and subject to change.")>]
110-
type FieldNotContainedDiagnosticExtendedData
111-
internal (symbolEnv: SymbolEnv, implTycon: Tycon, sigTycon: Tycon, signatureField: RecdField, implementationField: RecdField) =
94+
type FieldNotContainedDiagnosticExtendedData internal (symbolEnv: SymbolEnv, implTycon: Tycon, sigTycon: Tycon,
95+
signatureField: RecdField, implementationField: RecdField) =
11296
interface IFSharpDiagnosticExtendedData
97+
11398
member x.SignatureField = FSharpField(symbolEnv, RecdFieldRef.RecdFieldRef(mkLocalTyconRef sigTycon, signatureField.Id.idText))
114-
member x.ImplementationField = FSharpField(symbolEnv, RecdFieldRef.RecdFieldRef(mkLocalTyconRef implTycon, implementationField.Id.idText))
11599

116-
[<Experimental("This FCS API is experimental and subject to change.")>]
117-
type ValueNotContainedDiagnosticExtendedData
118-
internal (symbolEnv: SymbolEnv, signatureValue: Val, implValue: Val) =
100+
member x.ImplementationField =
101+
FSharpField(symbolEnv, RecdFieldRef.RecdFieldRef(mkLocalTyconRef implTycon, implementationField.Id.idText))
102+
103+
type ValueNotContainedDiagnosticExtendedData internal (symbolEnv: SymbolEnv, signatureValue: Val, implValue: Val) =
119104
interface IFSharpDiagnosticExtendedData
105+
120106
member x.SignatureValue = FSharpMemberOrFunctionOrValue(symbolEnv, mkLocalValRef signatureValue)
121107
member x.ImplementationValue = FSharpMemberOrFunctionOrValue(symbolEnv, mkLocalValRef implValue)
122108

123-
[<Experimental("This FCS API is experimental and subject to change.")>]
124-
type ArgumentsInSigAndImplMismatchExtendedData
125-
internal(sigArg: Ident, implArg: Ident) =
109+
type ArgumentsInSigAndImplMismatchExtendedData internal (sigArg: Ident, implArg: Ident) =
126110
interface IFSharpDiagnosticExtendedData
111+
127112
member x.SignatureName = sigArg.idText
128113
member x.ImplementationName = implArg.idText
129114
member x.SignatureRange = sigArg.idRange
130115
member x.ImplementationRange = implArg.idRange
131116

132-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
133-
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData
134-
internal(signatureType: Tycon, implementationType: Tycon) =
117+
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData internal (signatureType: Tycon, implementationType: Tycon) =
135118
interface IFSharpDiagnosticExtendedData
136-
member x.SignatureRange: range = signatureType.Range
137-
member x.ImplementationRange: range = implementationType.Range
119+
120+
member x.SignatureRange = signatureType.Range
121+
member x.ImplementationRange = implementationType.Range
138122

139123
open ExtendedData
140124

141-
type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: string, subcategory: string, errorNum: int, numberPrefix: string, extendedData: IFSharpDiagnosticExtendedData option) =
125+
type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: string, subcategory: string, errorNum: int,
126+
numberPrefix: string, extendedData: IFSharpDiagnosticExtendedData option) =
142127
member _.Range = m
143-
144128
member _.Severity = severity
145-
146129
member _.Message = message
147-
148130
member _.Subcategory = subcategory
149-
150131
member _.ErrorNumber = errorNum
151-
152132
member _.ErrorNumberPrefix = numberPrefix
153-
154133
member _.ErrorNumberText = numberPrefix + errorNum.ToString("0000")
155-
156134
member _.Start = m.Start
157-
158135
member _.End = m.End
159-
160136
member _.StartLine = m.Start.Line
161-
162137
member _.EndLine = m.End.Line
163-
164138
member _.StartColumn = m.Start.Column
165-
166139
member _.EndColumn = m.End.Column
167-
168140
member _.FileName = m.FileName
169141

170-
[<Experimental("This FCS API is experimental and subject to change.")>]
171142
member _.ExtendedData = extendedData
172143

173144
member _.WithStart newStart =
@@ -305,7 +276,7 @@ type DiagnosticsScope(flatErrors: bool) =
305276
| None -> err ""
306277

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

311282
let mutable errorCount = 0

src/Compiler/Symbols/FSharpDiagnostic.fsi

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,58 @@ open FSharp.Compiler.Symbols
1111
open FSharp.Compiler.Text
1212
open FSharp.Compiler.DiagnosticsLogger
1313

14-
module public ExtendedData =
14+
module ExtendedData =
1515
/// Information about the context of a type equation in type-mismatch-like diagnostic
16-
[<RequireQualifiedAccess; Experimental("This FCS API is experimental and subject to change.")>]
17-
type public DiagnosticContextInfo =
16+
[<RequireQualifiedAccess>]
17+
type DiagnosticContextInfo =
1818
/// No context was given
1919
| NoContext
20+
2021
/// The type equation comes from an IF expression
2122
| IfExpression
23+
2224
/// The type equation comes from an omitted else branch
2325
| OmittedElseBranch
26+
2427
/// The type equation comes from a type check of the result of an else branch
2528
| ElseBranchResult
29+
2630
/// The type equation comes from the verification of record fields
2731
| RecordFields
32+
2833
/// The type equation comes from the verification of a tuple in record fields
2934
| TupleInRecordFields
35+
3036
/// The type equation comes from a list or array constructor
3137
| CollectionElement
38+
3239
/// The type equation comes from a return in a computation expression
3340
| ReturnInComputationExpression
41+
3442
/// The type equation comes from a yield in a computation expression
3543
| YieldInComputationExpression
44+
3645
/// The type equation comes from a runtime type test
3746
| RuntimeTypeTest
38-
/// The type equation comes from an downcast where a upcast could be used
47+
48+
/// The type equation comes from a downcast where an upcast could be used
3949
| DowncastUsedInsteadOfUpcast
40-
/// The type equation comes from a return type of a pattern match clause (not the first clause)
50+
51+
/// The type equation comes from the return type of a pattern match clause (not the first clause)
4152
| FollowingPatternMatchClause
53+
4254
/// The type equation comes from a pattern match guard
4355
| PatternMatchGuard
56+
4457
/// The type equation comes from a sequence expression
4558
| SequenceExpression
4659

4760
/// Contextually-relevant data to each particular diagnostic
48-
[<Interface; Experimental("This FCS API is experimental and subject to change.")>]
49-
type public IFSharpDiagnosticExtendedData = interface end
61+
type IFSharpDiagnosticExtendedData = interface end
5062

5163
/// Additional data for diagnostics about obsolete attributes.
52-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
53-
type public ObsoleteDiagnosticExtendedData =
64+
[<Class>]
65+
type ObsoleteDiagnosticExtendedData =
5466
interface IFSharpDiagnosticExtendedData
5567

5668
/// Represents the DiagnosticId of the diagnostic
@@ -60,8 +72,8 @@ module public ExtendedData =
6072
member UrlFormat: string option
6173

6274
/// Additional data for diagnostics about experimental attributes.
63-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
64-
type public ExperimentalExtendedData =
75+
[<Class>]
76+
type ExperimentalExtendedData =
6577
interface IFSharpDiagnosticExtendedData
6678

6779
/// Represents the DiagnosticId of the diagnostic
@@ -71,69 +83,84 @@ module public ExtendedData =
7183
member UrlFormat: string option
7284

7385
/// Additional data for type-mismatch-like (usually with ErrorNumber = 1) diagnostics
74-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
75-
type public TypeMismatchDiagnosticExtendedData =
86+
[<Class>]
87+
type TypeMismatchDiagnosticExtendedData =
7688
interface IFSharpDiagnosticExtendedData
77-
/// Represents F# type expected in the current context
89+
90+
/// Represents the expected F# type in the current context
7891
member ExpectedType: FSharpType
79-
/// Represents F# type type actual in the current context
92+
93+
/// Represents the actual F# type in the current context
8094
member ActualType: FSharpType
95+
8196
/// The context in which the type mismatch was found
8297
member ContextInfo: DiagnosticContextInfo
98+
8399
/// Represents the information needed to format types
84100
member DisplayContext: FSharpDisplayContext
85101

86102
/// Additional data for 'This expression is a function value, i.e. is missing arguments' diagnostic
87-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
88-
type public ExpressionIsAFunctionExtendedData =
103+
[<Class>]
104+
type ExpressionIsAFunctionExtendedData =
89105
interface IFSharpDiagnosticExtendedData
106+
90107
/// Represents F# type of the expression
91108
member ActualType: FSharpType
92109

93110
/// Additional data for diagnostics about a field whose declarations differ in signature and implementation
94-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
95-
type public FieldNotContainedDiagnosticExtendedData =
111+
[<Class>]
112+
type FieldNotContainedDiagnosticExtendedData =
96113
interface IFSharpDiagnosticExtendedData
97-
/// Represents F# field in signature file
114+
115+
/// Represents F# field in the signature file
98116
member SignatureField: FSharpField
99-
/// Represents F# field in implementation file
117+
118+
/// Represents F# field in the implementation file
100119
member ImplementationField: FSharpField
101120

102121
/// Additional data for diagnostics about a value whose declarations differ in signature and implementation
103-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
104-
type public ValueNotContainedDiagnosticExtendedData =
122+
[<Class>]
123+
type ValueNotContainedDiagnosticExtendedData =
105124
interface IFSharpDiagnosticExtendedData
125+
106126
/// Represents F# value in signature file
107127
member SignatureValue: FSharpMemberOrFunctionOrValue
128+
108129
/// Represents F# value in implementation file
109130
member ImplementationValue: FSharpMemberOrFunctionOrValue
110131

111132
/// Additional data for 'argument names in the signature and implementation do not match' diagnostic
112-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
133+
[<Class>]
113134
type ArgumentsInSigAndImplMismatchExtendedData =
114135
interface IFSharpDiagnosticExtendedData
115-
/// Argument name in signature file
136+
137+
/// Argument name in the signature file
116138
member SignatureName: string
117-
/// Argument name in implementation file
139+
140+
/// Argument name in the implementation file
118141
member ImplementationName: string
119-
/// Argument identifier range within signature file
142+
143+
/// Argument identifier range within the signature file
120144
member SignatureRange: range
121-
/// Argument identifier range within implementation file
145+
146+
/// Argument identifier range within the implementation file
122147
member ImplementationRange: range
123148

124-
[<Class; Experimental("This FCS API is experimental and subject to change.")>]
149+
[<Class>]
125150
type DefinitionsInSigAndImplNotCompatibleAbbreviationsDifferExtendedData =
126151
interface IFSharpDiagnosticExtendedData
152+
127153
/// Range of the signature type identifier.
128154
member SignatureRange: range
155+
129156
/// Range of the implementation type identifier.
130157
member ImplementationRange: range
131158

132159
open ExtendedData
133160

134161
/// Represents a diagnostic produced by the F# compiler
135162
[<Class>]
136-
type public FSharpDiagnostic =
163+
type FSharpDiagnostic =
137164

138165
/// Gets the file name for the diagnostic
139166
member FileName: string
@@ -165,7 +192,7 @@ type public FSharpDiagnostic =
165192
/// Gets the message for the diagnostic
166193
member Message: string
167194

168-
/// Gets the sub-category for the diagnostic
195+
/// Gets the subcategory for the diagnostic
169196
member Subcategory: string
170197

171198
/// Gets the number for the diagnostic
@@ -177,7 +204,7 @@ type public FSharpDiagnostic =
177204
/// Gets the full error number text e.g "FS0031"
178205
member ErrorNumberText: string
179206

180-
/// Gets the contextually-relevant data to each particular diagnostic for things like code fixes
207+
/// Gets the contextually relevant data to each particular diagnostic for things like code fixes
181208
[<Experimental("This FCS API is experimental and subject to change.")>]
182209
member ExtendedData: IFSharpDiagnosticExtendedData option
183210

@@ -222,7 +249,7 @@ type internal DiagnosticsScope =
222249

223250
static member Protect<'T> : range -> (unit -> 'T) -> (string -> 'T) -> 'T
224251

225-
/// An error logger that capture errors, filtering them according to warning levels etc.
252+
/// An error logger that captures errors, filtering them according to warning levels etc.
226253
type internal CompilationDiagnosticLogger =
227254
inherit DiagnosticsLogger
228255

0 commit comments

Comments
 (0)