From 5cf670741afaa6eb9bc670f6693fbb82fc5b4c01 Mon Sep 17 00:00:00 2001 From: i10416 Date: Fri, 9 Feb 2024 17:13:47 +0900 Subject: [PATCH] fix(#i18645): overload ext method body in braces didn't compile `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`. --- .../src/dotty/tools/dotc/typer/ProtoTypes.scala | 4 +++- tests/pos/i18645.scala | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18645.scala diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 6b72f3a8b56e..9d5c1352b106 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -407,7 +407,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 diff --git a/tests/pos/i18645.scala b/tests/pos/i18645.scala new file mode 100644 index 000000000000..599396b678af --- /dev/null +++ b/tests/pos/i18645.scala @@ -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 }) \ No newline at end of file