Skip to content

Commit abced93

Browse files
committed
wip
1 parent 01192b1 commit abced93

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ exception ConstraintSolverTupleDiffLengths of displayEnv: DisplayEnv * contextIn
216216

217217
exception ConstraintSolverInfiniteTypes of displayEnv: DisplayEnv * contextInfo: ContextInfo * TType * TType * range * range
218218

219-
exception ConstraintSolverTypesNotInEqualityRelation of displayEnv: DisplayEnv * expectedTy: TType * actualTy: TType * range * range * ContextInfo
219+
exception ConstraintSolverTypesNotInEqualityRelation of displayEnv: DisplayEnv * TType * TType * range * range * ContextInfo
220220

221221
exception ConstraintSolverTypesNotInSubsumptionRelation of displayEnv: DisplayEnv * argTy: TType * paramTy: TType * callRange: range * parameterRange: range
222222

@@ -1756,7 +1756,7 @@ and SolveMemberConstraint (csenv: ConstraintSolverEnv) ignoreUnresolvedOverload
17561756
(minfos |> List.forall (fun (_, minfo) -> isIntegerTy g minfo.ApparentEnclosingType ) &&
17571757
( IsAddSubModType nm g argTy1 && IsBinaryOpOtherArgType g permitWeakResolution argTy2
17581758
|| IsAddSubModType nm g argTy2 && IsBinaryOpOtherArgType g permitWeakResolution argTy1)) ->
1759-
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace argTy1 argTy2
1759+
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace argTy2 argTy1
17601760
do! SolveTypeEqualsTypeKeepAbbrevs csenv ndeep m2 trace retTy argTy1
17611761
return TTraitBuiltIn
17621762

@@ -3184,8 +3184,6 @@ and SolveTypeEqualsTypeWithReport (csenv: ConstraintSolverEnv) ndeep m trace cxs
31843184
(fun () -> SolveTypeEqualsTypeKeepAbbrevsWithCxsln csenv ndeep m trace cxsln expectedTy actualTy)
31853185
(function
31863186
| AbortForFailedMemberConstraintResolution as err -> ErrorD err
3187-
| ConstraintSolverTypesNotInEqualityRelation(_, expectedTy, actualTy, _, _, _) as err ->
3188-
ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, expectedTy, actualTy, err, m))
31893187
| res -> ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, expectedTy, actualTy, res, m)))
31903188

31913189
and ArgsMustSubsumeOrConvert

src/Compiler/Checking/ConstraintSolver.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ exception ConstraintSolverInfiniteTypes of
104104

105105
exception ConstraintSolverTypesNotInEqualityRelation of
106106
displayEnv: DisplayEnv *
107-
expectedTy: TType *
108-
actualTy: TType *
107+
TType *
108+
TType *
109109
range *
110110
range *
111111
ContextInfo

src/Compiler/Symbols/FSharpDiagnostic.fs

Lines changed: 11 additions & 3 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,7 +25,6 @@ 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 =
@@ -199,11 +197,21 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str
199197

200198
match diagnostic.Exception with
201199
| ErrorFromAddingTypeEquation(_, displayEnv, expectedType, actualType, ConstraintSolverTupleDiffLengths(contextInfo = contextInfo), _)
202-
| ErrorFromAddingTypeEquation(_, displayEnv, expectedType, actualType, ConstraintSolverTypesNotInEqualityRelation(_, _, _, _, _, contextInfo), _)
203200
| ErrorsFromAddingSubsumptionConstraint(_, displayEnv, expectedType, actualType, _, contextInfo, _) ->
204201
let context = DiagnosticContextInfo.From(contextInfo)
205202
Some(TypeMismatchDiagnosticExtendedData(symbolEnv, displayEnv, expectedType, actualType, context))
206203

204+
| ErrorFromAddingTypeEquation(g, displayEnv, ty1, ty2, ConstraintSolverTypesNotInEqualityRelation(_, ty1b, ty2b, _, _, contextInfo), _) ->
205+
let expectedType, actualType =
206+
if typeEquiv g ty1 ty1b && typeEquiv g ty2 ty2b then
207+
ty1, ty2
208+
elif not (typeEquiv g ty1 ty2) then
209+
ty1, ty2
210+
else ty2b, ty1b
211+
212+
let context = DiagnosticContextInfo.From(contextInfo)
213+
Some(TypeMismatchDiagnosticExtendedData(symbolEnv, displayEnv, expectedType, actualType, context))
214+
207215
| ErrorFromAddingTypeEquation(_, displayEnv, expectedType, actualType, _, _)->
208216
Some(TypeMismatchDiagnosticExtendedData(symbolEnv, displayEnv, expectedType, actualType, DiagnosticContextInfo.NoContext))
209217

tests/FSharp.Compiler.ComponentTests/ErrorMessages/ExtendedDiagnosticDataTests.fs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
open FSharp.Compiler.Text
55
open FSharp.Compiler.Diagnostics
66
open FSharp.Compiler.Diagnostics.ExtendedData
7-
open FSharp.Test
87
open FSharp.Test.Compiler
98
open Xunit
109

@@ -144,16 +143,26 @@ if true then 1 else "a"
144143
Assert.Equal("int", typeMismatch.ExpectedType.Format(displayContext))
145144
Assert.Equal("string", typeMismatch.ActualType.Format(displayContext)))
146145

147-
[<Theory>]
148-
[<InlineData("""
146+
[<Fact>]
147+
let ``TypeMismatchDiagnosticExtendedData 08`` () =
148+
FSharp """
149149
type R = { Field1: int }
150150
let f (x: R) = "" + x.Field1
151-
""")>]
152-
[<InlineData("""
151+
"""
152+
|> typecheckResults
153+
|> checkDiagnostic
154+
(1, "The type 'int' does not match the type 'string'")
155+
(fun (typeMismatch: TypeMismatchDiagnosticExtendedData) ->
156+
let displayContext = typeMismatch.DisplayContext
157+
Assert.Equal(DiagnosticContextInfo.NoContext, typeMismatch.ContextInfo)
158+
Assert.Equal("string", typeMismatch.ExpectedType.Format(displayContext))
159+
Assert.Equal("int", typeMismatch.ActualType.Format(displayContext)))
160+
161+
[<Fact>]
162+
let ``TypeMismatchDiagnosticExtendedData 09`` () =
163+
FSharp """
153164
let x: string = 1
154-
""")>]
155-
let ``TypeMismatchDiagnosticExtendedData 08`` code =
156-
FSharp code
165+
"""
157166
|> typecheckResults
158167
|> checkDiagnostic
159168
(1, "This expression was expected to have type\n 'string' \nbut here has type\n 'int' ")

0 commit comments

Comments
 (0)