Skip to content

Commit 5eb8c2d

Browse files
committed
Fix #2901: Make asClass cast only when sure it is a class
1 parent 4f60767 commit 5eb8c2d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
101101
val Select(sup @ Super(_, mix), name) = sel
102102
val sym = sel.symbol
103103
assert(sup.symbol.exists, s"missing symbol in $sel: ${sup.tpe}")
104-
val clazz = sup.symbol.asClass
104+
val clazz = sup.symbol
105105

106106
if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.is(ParamForwarder))
107107
// ParamForwaders as installed ParamForwarding.scala do use super calls to vals
108108
ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.pos)
109109
else if (isDisallowed(sym))
110110
ctx.error(s"super not allowed here: use this.${sel.name} instead", sel.pos)
111111
else if (sym is Deferred) {
112-
val member = sym.overridingSymbol(clazz)
112+
val member = sym.overridingSymbol(clazz.asClass)
113113
if (!mix.name.isEmpty ||
114114
!member.exists ||
115115
!((member is AbsOverride) && member.isIncompleteIn(clazz)))

tests/neg/i2901.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo {
2+
def foo = 4
3+
}
4+
object Bar extends Foo {
5+
inline def bar = super[Foo].foo // error
6+
}
7+
object Main {
8+
Bar.bar
9+
}

0 commit comments

Comments
 (0)