Skip to content

Commit

Permalink
Fix spurious "nullary overrides nilary" warning
Browse files Browse the repository at this point in the history
```
interface A { int f(); }          // Java
trait B extends A { def f: Int }  // Scala
trait C { def f = 2 }
class T extends B with C
```

Namer adds an empty parameter list `()` to `B.f`.
There's no override warning at `B.f` because `A.f` is defined in Java.

In class `T`, `C.f` (without parameter list) overrides `B.f()` (with an
empty parameter list - added by Namer). There should be no warning.
  • Loading branch information
lrytz committed Sep 1, 2023
1 parent f7e30a6 commit 96d74ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ abstract class RefChecks extends Transform {
warnAdaptedNullaryOverride()
}
else if (member.paramLists.isEmpty) {
// NullaryOverrideAdapted is only added to symbols being compiled, so check for a mismatch
// if both symbols are mixed in from the classpath
if (!member.isStable && other.paramLists.nonEmpty && !exempted)
// Definitions that directly override get a parameter list and a `NullaryOverrideAdapted` attachment
// in Namers. Here we also warn when there's a mismatch between two mixed-in members.
if (!member.isStable && other.paramLists.nonEmpty && !exempted && !other.overrides.exists(javaDetermined))
warnAdaptedNullaryOverride()
}
else if (other.paramLists.isEmpty) {
Expand Down
3 changes: 3 additions & 0 deletions test/files/pos/t12858/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface A {
int f();
}
9 changes: 9 additions & 0 deletions test/files/pos/t12858/B.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// scalac: -Werror

trait B1 extends A { def f: Int }
trait C1 { def f = 2 }
class T1 extends B1 with C1

trait B2 extends A { def f: Int = 1}
trait C2 { self: B2 => override def f = 2 }
class T2 extends B2 with C2

0 comments on commit 96d74ac

Please sign in to comment.