Skip to content

Fix #9437: Skip $asInstanceOf$ in error message #9447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i9437.check
Original file line number Diff line number Diff line change
@@ -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`
7 changes: 7 additions & 0 deletions tests/neg/i9437.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Bag extends reflect.Selectable

@main def Test =
val x = new Bag:
val f1 = 23

println(x.f1()) // error