Skip to content

Commit

Permalink
fix(#i18645): overload ext method body in braces didn't compile
Browse files Browse the repository at this point in the history
`tryWithImplicitOnQualifier` returned without attempting `tryInsertImplicitOnQualifier`,
which prevented the compiler from finding overloaded method, because `hasInnerErrors`
in `ProtoTypes` picked up the inner error propagated back from outer error.

When compiling `x.pprint(()=> { 123 })` before this commit, in `hasInnerErrors`,
`t` contains two sub trees; `Block(stmt, expr)` and `stmt`. The span of the former matches
the span of `t`, but that of the latter does not, which caused `hasInnerErrors` to return `true`,
but the error from the latter is duplicated with the error of parent tree `t`.

[Cherry-picked 5cf6707]
  • Loading branch information
i10416 authored and WojciechMazur committed Jul 1, 2024
1 parent 45cef44 commit b49f016
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ object ProtoTypes {
case closureDef(mdef) => hasInnerErrors(mdef.rhs)
case _ =>
t.existsSubTree { t1 =>
if t1.typeOpt.isError && t1.span.toSynthetic != t.span.toSynthetic then
if t1.typeOpt.isError
&& t.span.toSynthetic != t1.span.toSynthetic
&& t.typeOpt != t1.typeOpt then
typr.println(i"error subtree $t1 of $t with ${t1.typeOpt}, spans = ${t1.span}, ${t.span}")
true
else
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i18645.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait Printable {
def pprint(v: () => String): Unit = {
println(v())
}
}

extension (ctx: Printable)
def pprint(f: () => Int): Unit = {
ctx.pprint(() => f().toString)
}

val x = new Printable {}

def test =
x.pprint(() => ( 234 ))
x.pprint(() => { 123 })

0 comments on commit b49f016

Please sign in to comment.