Skip to content

Commit ef763b9

Browse files
committed
Refactor checkConformsExpr to allow flexibility in the error reporting
1 parent db11bb7 commit ef763b9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,10 @@ class CheckCaptures extends Recheck, SymTransformer:
13221322
* where local capture roots are instantiated to root variables.
13231323
*/
13241324
override def checkConformsExpr(actual: Type, expected: Type, tree: Tree, addenda: Addenda)(using Context): Type =
1325+
testAdapted(actual, expected, tree, addenda)(err.typeMismatch)
1326+
1327+
inline def testAdapted(actual: Type, expected: Type, tree: Tree, addenda: Addenda)
1328+
(fail: (Tree, Type, Addenda) => Unit)(using Context): Type =
13251329
var expected1 = alignDependentFunction(expected, actual.stripCapturing)
13261330
val actualBoxed = adapt(actual, expected1, tree)
13271331
//println(i"check conforms $actualBoxed <<< $expected1")
@@ -1332,18 +1336,16 @@ class CheckCaptures extends Recheck, SymTransformer:
13321336
TypeComparer.compareResult(isCompatible(actualBoxed, expected1)) match
13331337
case TypeComparer.CompareResult.Fail(notes) =>
13341338
capt.println(i"conforms failed for ${tree}: $actual vs $expected")
1335-
err.typeMismatch(tree.withType(actualBoxed), expected1,
1336-
addApproxAddenda(
1337-
addenda ++ errorNotes(notes),
1338-
expected1))
1339+
fail(tree.withType(actualBoxed), expected1,
1340+
addApproxAddenda(addenda ++ errorNotes(notes), expected1))
13391341
actual
13401342
case /*OK*/ _ =>
13411343
if debugSuccesses then tree match
1342-
case Ident(_) =>
1343-
println(i"SUCCESS $tree for $actual <:< $expected:\n${TypeComparer.explained(_.isSubType(actualBoxed, expected1))}")
1344-
case _ =>
1344+
case Ident(_) =>
1345+
println(i"SUCCESS $tree for $actual <:< $expected:\n${TypeComparer.explained(_.isSubType(actualBoxed, expected1))}")
1346+
case _ =>
13451347
actualBoxed
1346-
end checkConformsExpr
1348+
end testAdapted
13471349

13481350
/** Turn `expected` into a dependent function when `actual` is dependent. */
13491351
private def alignDependentFunction(expected: Type, actual: Type)(using Context): Type =

0 commit comments

Comments
 (0)