Skip to content

Commit 821e496

Browse files
committed
wip
1 parent 804090d commit 821e496

40 files changed

+580
-163
lines changed

src/Compiler/Checking/SignatureConformance.fs

Lines changed: 41 additions & 40 deletions
Large diffs are not rendered by default.

src/Compiler/Checking/SignatureConformance.fsi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module internal FSharp.Compiler.SignatureConformance
77
open System.Text
88

99
open FSharp.Compiler
10+
open FSharp.Compiler.Syntax
1011
open FSharp.Compiler.Text
1112
open FSharp.Compiler.TypedTree
1213
open FSharp.Compiler.TypedTreeOps
@@ -26,10 +27,12 @@ exception UnionCaseNotContained of DisplayEnv * InfoReader * Tycon * UnionCase *
2627

2728
exception FSharpExceptionNotContained of DisplayEnv * InfoReader * Tycon * Tycon * (string * string -> string)
2829

29-
exception FieldNotContained of DisplayEnv * InfoReader * Tycon * RecdField * RecdField * (string * string -> string)
30+
exception FieldNotContained of DisplayEnv * InfoReader * Tycon * Tycon * RecdField * RecdField * (string * string -> string)
3031

3132
exception InterfaceNotRevealed of DisplayEnv * TType * range
3233

34+
exception ArgumentsInSigAndImplMismatch of sigArg: Ident * implArg: Ident
35+
3336
type Checker =
3437

3538
new:

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type Exception with
7979

8080
member exn.DiagnosticRange =
8181
match exn with
82+
| ArgumentsInSigAndImplMismatch(_, implArg) -> Some implArg.idRange
8283
| ErrorFromAddingConstraint (_, exn2, _) -> exn2.DiagnosticRange
8384
#if !NO_TYPEPROVIDERS
8485
| TypeProviders.ProvidedTypeResolutionNoRange exn -> exn.DiagnosticRange
@@ -156,7 +157,7 @@ type Exception with
156157
| IndeterminateType m
157158
| TyconBadArgs (_, _, _, m) -> Some m
158159

159-
| FieldNotContained (_, _, _, arf, _, _) -> Some arf.Range
160+
| FieldNotContained (_, _, _, _, arf, _, _) -> Some arf.Range
160161
| ValueNotContained (_, _, _, aval, _, _) -> Some aval.Range
161162
| UnionCaseNotContained (_, _, _, aval, _, _) -> Some aval.Id.idRange
162163
| FSharpExceptionNotContained (_, _, aexnc, _, _) -> Some aexnc.Range
@@ -318,6 +319,7 @@ type Exception with
318319
| BadEventTransformation _ -> 91
319320
| HashLoadedScriptConsideredSource _ -> 92
320321
| UnresolvedConversionOperator _ -> 93
322+
| ArgumentsInSigAndImplMismatch _ -> 3218
321323
// avoid 94-100 for safety
322324
| ObsoleteError _ -> 101
323325
#if !NO_TYPEPROVIDERS
@@ -599,6 +601,7 @@ module OldStyleMessages =
599601
let LoadedSourceNotFoundIgnoringE () = Message("LoadedSourceNotFoundIgnoring", "%s")
600602
let MSBuildReferenceResolutionErrorE () = Message("MSBuildReferenceResolutionError", "%s%s")
601603
let TargetInvocationExceptionWrapperE () = Message("TargetInvocationExceptionWrapper", "%s")
604+
let ArgumentsInSigAndImplMismatchE () = Message("ArgumentsInSigAndImplMismatch", "%s%s")
602605

603606
#if DEBUG
604607
let mutable showParserStackOnParseError = false
@@ -1570,7 +1573,7 @@ type Exception with
15701573
)
15711574
)
15721575

1573-
| FieldNotContained (denv, infoReader, enclosingTycon, v1, v2, f) ->
1576+
| FieldNotContained (denv, infoReader, enclosingTycon, _, v1, v2, f) ->
15741577
let enclosingTcref = mkLocalEntityRef enclosingTycon
15751578

15761579
os.AppendString(
@@ -1868,6 +1871,9 @@ type Exception with
18681871

18691872
| MSBuildReferenceResolutionError (code, message, _) -> os.AppendString(MSBuildReferenceResolutionErrorE().Format message code)
18701873

1874+
| ArgumentsInSigAndImplMismatch(sigArg, implArg) ->
1875+
os.AppendString(ArgumentsInSigAndImplMismatchE().Format sigArg.idText implArg.idText)
1876+
18711877
// Strip TargetInvocationException wrappers
18721878
| :? TargetInvocationException as exn -> exn.InnerException.Output(os, suggestNames)
18731879

src/Compiler/FSComp.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ notAFunctionButMaybeIndexerWithName2,"This value is not a function and cannot be
14911491
notAFunctionButMaybeIndexer2,"This expression is not a function and cannot be applied. Did you intend to access the indexer via 'expr[index]'?"
14921492
3217,notAFunctionButMaybeIndexerErrorCode,""
14931493
notAFunctionButMaybeDeclaration,"This value is not a function and cannot be applied. Did you forget to terminate a declaration?"
1494-
3218,ArgumentsInSigAndImplMismatch,"The argument names in the signature '%s' and implementation '%s' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling."
14951494
3219,pickleUnexpectedNonZero,"An error occurred while reading the F# metadata of assembly '%s'. A reserved construct was utilized. You may need to upgrade your F# compiler or use an earlier version of the assembly that doesn't make use of a specific construct."
14961495
3220,tcTupleMemberNotNormallyUsed,"This method or property is not normally used from F# code, use an explicit tuple pattern for deconstruction instead."
14971496
3221,implicitlyDiscardedInSequenceExpression,"This expression returns a value of type '%s' but is implicitly discarded. Consider using 'let' to bind the result to a name, e.g. 'let result = expression'. If you intended to use the expression as a value in the sequence then use an explicit 'yield'."

src/Compiler/FSStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@
11131113
<data name="ErrorFromAddingTypeEquationTuples" xml:space="preserve">
11141114
<value>Type mismatch. Expecting a tuple of length {0} of type\n {1} \nbut given a tuple of length {2} of type\n {3} {4}\n</value>
11151115
</data>
1116+
<data name="ArgumentsInSigAndImplMismatch" xml:space="preserve">
1117+
<value>The argument names in the signature '{0}' and implementation '{1}' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling.</value>
1118+
</data>
11161119
<data name="Parser.TOKEN.WHILE.BANG" xml:space="preserve">
11171120
<value>keyword 'while!'</value>
11181121
</data>

src/Compiler/FSharp.Compiler.Service.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@
440440
<Compile Include="Driver\fsc.fs" />
441441

442442
<!-- the symbol API. -->
443-
<Compile Include="Symbols\FSharpDiagnostic.fsi" />
444-
<Compile Include="Symbols\FSharpDiagnostic.fs" />
445443
<Compile Include="Symbols\SymbolHelpers.fsi" />
446444
<Compile Include="Symbols\SymbolHelpers.fs" />
447445
<Compile Include="Symbols\Symbols.fsi" />
448446
<Compile Include="Symbols\Symbols.fs" />
447+
<Compile Include="Symbols\FSharpDiagnostic.fsi" />
448+
<Compile Include="Symbols\FSharpDiagnostic.fs" />
449449
<Compile Include="Symbols\Exprs.fsi" />
450450
<Compile Include="Symbols\Exprs.fs" />
451451
<Compile Include="Symbols\SymbolPatterns.fsi" />

src/Compiler/Interactive/fsi.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4703,7 +4703,7 @@ type FsiEvaluationSession
47034703
let errs = diagnosticsLogger.GetDiagnostics()
47044704

47054705
let errorInfos =
4706-
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true, tcConfigB.flatErrors)
4706+
DiagnosticHelpers.CreateDiagnostics(errorOptions, true, scriptFile, errs, true, tcConfigB.flatErrors, None)
47074707

47084708
let userRes =
47094709
match res with

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,21 +2411,15 @@ module internal ParseAndCheckFile =
24112411
let fileInfo = sourceText.GetLastCharacterPosition()
24122412

24132413
let collectOne severity diagnostic =
2414-
for diagnostic in
2415-
DiagnosticHelpers.ReportDiagnostic(
2416-
options,
2417-
false,
2418-
mainInputFileName,
2419-
fileInfo,
2420-
diagnostic,
2421-
severity,
2422-
suggestNamesForErrors,
2423-
flatErrors
2424-
) do
2425-
diagnosticsCollector.Add diagnostic
2426-
2427-
if severity = FSharpDiagnosticSeverity.Error then
2428-
errorCount <- errorCount + 1
2414+
// 1. Extended diagnostic data should be created after typechecking because it requires a valid SymbolEnv
2415+
// 2. Diagnostic message should be created during the diagnostic sink, because after typechecking
2416+
// the formatting of types in it may change (for example, 'a to obj)
2417+
//
2418+
// So we'll create a diagnostic later, but cache the FormatCore message now
2419+
diagnostic.Exception.Data["CachedFormatCore"] <- diagnostic.FormatCore(flatErrors, suggestNamesForErrors)
2420+
diagnosticsCollector.Add(struct(diagnostic, severity))
2421+
if severity = FSharpDiagnosticSeverity.Error then
2422+
errorCount <- errorCount + 1
24292423

24302424
// This function gets called whenever an error happens during parsing or checking
24312425
let diagnosticSink severity (diagnostic: PhasedDiagnostic) =
@@ -2464,15 +2458,18 @@ module internal ParseAndCheckFile =
24642458
// Public members
24652459
member _.DiagnosticsLogger = diagnosticsLogger
24662460

2467-
member _.CollectedDiagnostics = diagnosticsCollector.ToArray()
2468-
24692461
member _.ErrorCount = errorCount
24702462

24712463
member _.DiagnosticOptions
24722464
with set opts = options <- opts
24732465

24742466
member _.AnyErrors = errorCount > 0
24752467

2468+
member _.CollectedDiagnostics(symbolEnv: SymbolEnv option) =
2469+
[| for struct(diagnostic, severity) in diagnosticsCollector do
2470+
yield! DiagnosticHelpers.ReportDiagnostic(options, false, mainInputFileName, fileInfo, diagnostic, severity,
2471+
suggestNamesForErrors, flatErrors, symbolEnv) |]
2472+
24762473
let getLightSyntaxStatus fileName options =
24772474
let indentationAwareSyntaxOnByDefault =
24782475
List.exists (FileSystemUtils.checkSuffix fileName) FSharpIndentationAwareSyntaxFileSuffixes
@@ -2682,7 +2679,7 @@ module internal ParseAndCheckFile =
26822679
errHandler.DiagnosticsLogger.StopProcessingRecovery e range0 // don't re-raise any exceptions, we must return None.
26832680
EmptyParsedInput(fileName, (isLastCompiland, isExe)))
26842681

2685-
errHandler.CollectedDiagnostics, parseResult, errHandler.AnyErrors
2682+
errHandler.CollectedDiagnostics(None), parseResult, errHandler.AnyErrors
26862683

26872684
let ApplyLoadClosure
26882685
(
@@ -2884,12 +2881,12 @@ module internal ParseAndCheckFile =
28842881
return ((tcState.TcEnvFromSignatures, EmptyTopAttrs, [], [ mty ]), tcState)
28852882
}
28862883

2887-
let errors = errHandler.CollectedDiagnostics
2884+
let (tcEnvAtEnd, _, implFiles, ccuSigsForFiles), tcState = resOpt
28882885

2886+
let symbolEnv = SymbolEnv(tcGlobals, tcState.Ccu, Some tcState.CcuSig, tcImports)
2887+
let errors = errHandler.CollectedDiagnostics(Some symbolEnv)
28892888
let res =
2890-
match resOpt with
2891-
| (tcEnvAtEnd, _, implFiles, ccuSigsForFiles), tcState ->
2892-
TypeCheckInfo(
2889+
TypeCheckInfo(
28932890
tcConfig,
28942891
tcGlobals,
28952892
List.head ccuSigsForFiles,

src/Compiler/Service/IncrementalBuild.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ type IncrementalBuilder(initialState: IncrementalBuilderInitialState, state: Inc
16421642
Array.ofList delayedLogger.Diagnostics, false
16431643
diagnostics
16441644
|> Array.map (fun (diagnostic, severity) ->
1645-
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors, flatErrors))
1645+
FSharpDiagnostic.CreateFromException(diagnostic, severity, range.Zero, suggestNamesForErrors, flatErrors, None))
16461646

16471647
return builderOpt, diagnostics
1648-
}
1648+
}

src/Compiler/Service/service.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module CompileHelpers =
106106
{ new DiagnosticsLogger("CompileAPI") with
107107

108108
member _.DiagnosticSink(diag, isError) =
109-
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true, flatErrors)) // Suggest names for errors
109+
diagnostics.Add(FSharpDiagnostic.CreateFromException(diag, isError, range0, true, flatErrors, None)) // Suggest names for errors
110110

111111
member _.ErrorCount =
112112
diagnostics
@@ -556,7 +556,8 @@ type BackgroundCompiler
556556
fileName,
557557
parseDiagnostics,
558558
suggestNamesForErrors,
559-
builder.TcConfig.flatErrors
559+
builder.TcConfig.flatErrors,
560+
None
560561
)
561562

562563
let diagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
@@ -856,6 +857,7 @@ type BackgroundCompiler
856857
let tcDependencyFiles = tcInfo.tcDependencyFiles
857858
let tcDiagnostics = tcInfo.TcDiagnostics
858859
let diagnosticsOptions = builder.TcConfig.diagnosticsOptions
860+
let symbolEnv = SymbolEnv(tcProj.TcGlobals, tcInfo.tcState.Ccu, Some tcInfo.tcState.CcuSig, tcProj.TcImports) |> Some
859861

860862
let parseDiagnostics =
861863
DiagnosticHelpers.CreateDiagnostics(
@@ -864,7 +866,8 @@ type BackgroundCompiler
864866
fileName,
865867
parseDiagnostics,
866868
suggestNamesForErrors,
867-
builder.TcConfig.flatErrors
869+
builder.TcConfig.flatErrors,
870+
None
868871
)
869872

870873
let parseDiagnostics = [| yield! creationDiags; yield! parseDiagnostics |]
@@ -876,7 +879,8 @@ type BackgroundCompiler
876879
fileName,
877880
tcDiagnostics,
878881
suggestNamesForErrors,
879-
builder.TcConfig.flatErrors
882+
builder.TcConfig.flatErrors,
883+
symbolEnv
880884
)
881885

882886
let tcDiagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
@@ -1029,6 +1033,7 @@ type BackgroundCompiler
10291033
let tcEnvAtEnd = tcInfo.tcEnvAtEndOfFile
10301034
let tcDiagnostics = tcInfo.TcDiagnostics
10311035
let tcDependencyFiles = tcInfo.tcDependencyFiles
1036+
let symbolEnv = SymbolEnv(tcProj.TcGlobals, tcInfo.tcState.Ccu, Some tcInfo.tcState.CcuSig, tcProj.TcImports) |> Some
10321037

10331038
let tcDiagnostics =
10341039
DiagnosticHelpers.CreateDiagnostics(
@@ -1037,7 +1042,8 @@ type BackgroundCompiler
10371042
fileName,
10381043
tcDiagnostics,
10391044
suggestNamesForErrors,
1040-
builder.TcConfig.flatErrors
1045+
builder.TcConfig.flatErrors,
1046+
symbolEnv
10411047
)
10421048

10431049
let diagnostics = [| yield! creationDiags; yield! tcDiagnostics |]
@@ -1204,7 +1210,7 @@ type BackgroundCompiler
12041210
let diags =
12051211
loadClosure.LoadClosureRootFileDiagnostics
12061212
|> List.map (fun (exn, isError) ->
1207-
FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false, options.OtherOptions |> Array.contains "--flaterrors"))
1213+
FSharpDiagnostic.CreateFromException(exn, isError, range.Zero, false, options.OtherOptions |> Array.contains "--flaterrors", None))
12081214

12091215
return options, (diags @ diagnostics.Diagnostics)
12101216
}

0 commit comments

Comments
 (0)