Skip to content

Commit 18a6b91

Browse files
committed
Show synthesizd tree for type mismatch errors in CC
In capture checking, a type mismatch might happen for a synthesized tree (say from implicit search). It can be helpful to show this tree. Before capture checking a helpful message is less likely since we don't synthesize implicit trees that then don't match under the standard typing rules.
1 parent 1284bc4 commit 18a6b91

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ class CheckCaptures extends Recheck, SymTransformer:
15811581
* where local capture roots are instantiated to root variables.
15821582
*/
15831583
override def checkConformsExpr(actual: Type, expected: Type, tree: Tree, notes: List[Note])(using Context): Type =
1584-
try testAdapted(actual, expected, tree, notes: List[Note])(err.typeMismatch)
1584+
try testAdapted(actual, expected, tree, notes)(err.typeMismatch)
15851585
catch case ex: AssertionError =>
15861586
println(i"error while checking $tree: $actual against $expected")
15871587
throw ex

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import config.Feature
1414
import reporting.*
1515
import Message.Note
1616
import collection.mutable
17+
import cc.isCaptureChecking
1718

1819
object ErrorReporting {
1920

@@ -190,7 +191,13 @@ object ErrorReporting {
190191
case _ =>
191192
Nil
192193

193-
errorTree(tree, TypeMismatch(treeTp, expectedTp, Some(tree), notes ++ missingElse))
194+
def badTreeNote =
195+
val span = tree.span
196+
if tree.span.isZeroExtent && isCaptureChecking then
197+
Note(i"\n\nThe error occurred for a synthesized tree: $tree") :: Nil
198+
else Nil
199+
200+
errorTree(tree, TypeMismatch(treeTp, expectedTp, Some(tree), notes ++ missingElse ++ badTreeNote))
194201
}
195202

196203
/** A subtype log explaining why `found` does not conform to `expected` */

tests/neg-custom-args/captures/boundary.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
|
4646
| Note that capability cap is not included in capture set {cap²}.
4747
|
48+
| The error occurred for a synthesized tree: _
49+
|
4850
| where: ^ and cap² refer to the universal root capability
4951
| ^² and cap refer to a fresh root capability created in package <empty>
5052
6 | boundary[Unit]: l2 ?=>

0 commit comments

Comments
 (0)