Skip to content

Overriding Java varargs parameter of overloaded method requires explicit Array syntax #13043

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

Closed
ScoreUnder opened this issue Jul 10, 2021 · 0 comments · Fixed by #13066
Closed
Milestone

Comments

@ScoreUnder
Copy link

Compiler version

3.0.0 and 3.0.1

Minimized code

intf.java

interface Intf {
    public void thing(int x);
    public void thing(String... y);
}

impl.scala

class Impl extends Intf {
  override def thing(x: Int) = ???
  override def thing(y: String*) = ???
}

Output

[error] -- Error: /home/score/varargs-overloading/src/main/scala/impl.scala:1:6 --------
[error] 1 |class Impl extends Intf {
[error]   |      ^
[error]   |class Impl needs to be abstract, since def thing(y: Array[? <: String]): Unit in trait Intf is not defined 
[error]   |(The class implements members with different types: List(override def thing(y: Seq[String]): Nothing in class Impl, override def thing(x: Int): Unit in class Impl)%
[error]   |  %)
[error] -- [E038] Declaration Error: /home/score/varargs-overloading/src/main/scala/impl.scala:3:15 
[error] 3 |  override def thing(y: String*) = ???
[error]   |               ^
[error]   |    method thing has a different signature than the overridden declaration

Expectation

Like in Scala 2, this should be valid code.

The error can be worked around by using an Array type directly (not compatible with scala 2's behaviour) or by renaming/removing the overloads on the interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants