Skip to content

Commit 37a5443

Browse files
authored
Merge pull request #4792 from dotty-staging/fix-4753
Fix #4753: Direct method should keep `Override` if overriden nonempty
2 parents 76972ab + 0a7ddea commit 37a5443

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ object ShortcutImplicits {
181181
}
182182

183183
/** A new `m$direct` method to accompany the given method `m` */
184-
private def newShortcutMethod(sym: Symbol)(implicit ctx: Context): Symbol =
185-
sym.copy(
184+
private def newShortcutMethod(sym: Symbol)(implicit ctx: Context): Symbol = {
185+
val direct = sym.copy(
186186
name = DirectMethodName(sym.name.asTermName).asInstanceOf[sym.ThisName],
187-
flags = sym.flags &~ Override | Synthetic,
187+
flags = sym.flags | Synthetic,
188188
info = directInfo(sym.info))
189+
if (direct.allOverriddenSymbols.isEmpty) direct.resetFlag(Override)
190+
direct
191+
}
189192

190193
def shortcutMethod(sym: Symbol, phase: DenotTransformer)(implicit ctx: Context) =
191194
sym.owner.info.decl(DirectMethodName(sym.name.asTermName))

tests/pos/i4753b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Foo1 {
2+
def foo: implicit String => Int = 1
3+
}
4+
5+
class Foo2 extends Foo1 {
6+
override def foo: implicit String => Int = 2
7+
}

0 commit comments

Comments
 (0)