From a26b2c1e7d94b8b47e39089362d8f30f2d5bd32e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 27 Jul 2020 16:48:48 +0200 Subject: [PATCH] Fix #9437: Skip $asInstanceOf$ in error message Skip synthetic typecase $asInstanceOf$ when showing method symbol in error message --- .../src/dotty/tools/dotc/reporting/messages.scala | 12 ++++++++++-- tests/neg/i9437.check | 6 ++++++ tests/neg/i9437.scala | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i9437.check create mode 100644 tests/neg/i9437.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 9de881883848..d0958eb4dd03 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -1279,12 +1279,20 @@ import ast.tpd class MethodDoesNotTakeParameters(tree: tpd.Tree)(using Context) extends TypeMsg(MethodDoesNotTakeParametersId) { - def methodSymbol: Symbol = tpd.methPart(tree).symbol + def methodSymbol: Symbol = + def recur(t: tpd.Tree): Symbol = + val sym = tpd.methPart(t).symbol + if sym == defn.Any_typeCast then + t match + case TypeApply(Select(qual, _), _) => recur(qual) + case _ => sym + else sym + recur(tree) def msg = { val more = if (tree.isInstanceOf[tpd.Apply]) " more" else "" val meth = methodSymbol - val methStr = if (meth.exists) methodSymbol.showLocated else "expression" + val methStr = if (meth.exists) meth.showLocated else "expression" em"$methStr does not take$more parameters" } diff --git a/tests/neg/i9437.check b/tests/neg/i9437.check new file mode 100644 index 000000000000..d0b2226e5a0c --- /dev/null +++ b/tests/neg/i9437.check @@ -0,0 +1,6 @@ +-- [E050] Type Error: tests/neg/i9437.scala:7:10 ----------------------------------------------------------------------- +7 | println(x.f1()) // error + | ^^^^ + | method selectDynamic in trait Selectable does not take parameters + +longer explanation available when compiling with `-explain` diff --git a/tests/neg/i9437.scala b/tests/neg/i9437.scala new file mode 100644 index 000000000000..13cb2e74dc7a --- /dev/null +++ b/tests/neg/i9437.scala @@ -0,0 +1,7 @@ +class Bag extends reflect.Selectable + +@main def Test = + val x = new Bag: + val f1 = 23 + + println(x.f1()) // error \ No newline at end of file