Skip to content

Commit 0f2d1a3

Browse files
committed
Typer: Refine position when catching top-level TypeError
Intended to avoid the need for #4511.
1 parent 2040fb2 commit 0f2d1a3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,13 @@ class Typer extends Namer
18571857
assertPositioned(tree)
18581858
try adapt(typedUnadapted(tree, pt, locked), pt, locked)
18591859
catch {
1860-
case ex: TypeError => errorTree(tree, ex.toMessage)
1860+
case ex: TypeError =>
1861+
// This is equivalent to errorTree(tree, ex.toMessage) but
1862+
// uses tree.pos.focus instead of tree.pos. We use this because:
1863+
// - since tree can be a top-level definition, tree.pos can point to the whole definition
1864+
// - that would in turn hide all other type errors inside tree.
1865+
// TODO: might be even better to store positions inside TypeErrors.
1866+
tree withType errorType(ex.toMessage, tree.pos.focus)
18611867
}
18621868
}
18631869

0 commit comments

Comments
 (0)