Skip to content

Commit cdb8e93

Browse files
committed
wip
1 parent 2f77692 commit cdb8e93

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 4 additions & 2 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 * TType * TType * range * range * ContextInfo
219+
exception ConstraintSolverTypesNotInEqualityRelation of displayEnv: DisplayEnv * expectedTy: TType * actualTy: TType * range * range * ContextInfo
220220

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

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

@@ -3171,6 +3171,8 @@ and SolveTypeEqualsTypeWithReport (csenv: ConstraintSolverEnv) ndeep m trace cxs
31713171
(fun () -> SolveTypeEqualsTypeKeepAbbrevsWithCxsln csenv ndeep m trace cxsln expectedTy actualTy)
31723172
(function
31733173
| AbortForFailedMemberConstraintResolution as err -> ErrorD err
3174+
| ConstraintSolverTypesNotInEqualityRelation(_, expectedTy, actualTy, _, _, _) as err ->
3175+
ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, expectedTy, actualTy, err, m))
31743176
| res -> ErrorD (ErrorFromAddingTypeEquation(csenv.g, csenv.DisplayEnv, expectedTy, actualTy, res, m)))
31753177

31763178
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-
TType *
108-
TType *
107+
expectedTy: TType *
108+
actualTy: TType *
109109
range *
110110
range *
111111
ContextInfo

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,25 @@ if true then 1 else "a"
144144
Assert.Equal("int", typeMismatch.ExpectedType.Format(displayContext))
145145
Assert.Equal("string", typeMismatch.ActualType.Format(displayContext)))
146146

147+
[<Theory>]
148+
[<InlineData("""
149+
type R = { Field1: int }
150+
let f (x: R) = "" + x.Field1
151+
""")>]
152+
[<InlineData("""
153+
let x: string = 1
154+
""")>]
155+
let ``TypeMismatchDiagnosticExtendedData 08`` code =
156+
FSharp code
157+
|> typecheckResults
158+
|> checkDiagnostic
159+
(1, "This expression was expected to have type\n 'string' \nbut here has type\n 'int' ")
160+
(fun (typeMismatch: TypeMismatchDiagnosticExtendedData) ->
161+
let displayContext = typeMismatch.DisplayContext
162+
Assert.Equal(DiagnosticContextInfo.NoContext, typeMismatch.ContextInfo)
163+
Assert.Equal("string", typeMismatch.ExpectedType.Format(displayContext))
164+
Assert.Equal("int", typeMismatch.ActualType.Format(displayContext)))
165+
147166
[<Theory>]
148167
[<InlineData true>]
149168
[<InlineData false>]

0 commit comments

Comments
 (0)