Skip to content

Fix #2901: Make asClass cast only when sure it is a class #2902

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 27, 2017
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
val Select(sup @ Super(_, mix), name) = sel
val sym = sel.symbol
assert(sup.symbol.exists, s"missing symbol in $sel: ${sup.tpe}")
val clazz = sup.symbol.asClass
val clazz = sup.symbol

if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.is(ParamForwarder))
// ParamForwaders as installed ParamForwarding.scala do use super calls to vals
ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.pos)
else if (isDisallowed(sym))
ctx.error(s"super not allowed here: use this.${sel.name} instead", sel.pos)
else if (sym is Deferred) {
val member = sym.overridingSymbol(clazz)
val member = sym.overridingSymbol(clazz.asClass)
if (!mix.name.isEmpty ||
!member.exists ||
!((member is AbsOverride) && member.isIncompleteIn(clazz)))
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i2901.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait Foo {
def foo = 4
}
object Bar extends Foo {
inline def bar = super[Foo].foo // error
}
object Main {
Bar.bar
}