Skip to content

Varargs override with Seq should clash more #12662

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
som-snytt opened this issue May 31, 2021 · 0 comments · Fixed by #16836
Closed

Varargs override with Seq should clash more #12662

som-snytt opened this issue May 31, 2021 · 0 comments · Fixed by #16836
Labels
itype:bug Spree Suitable for a future Spree
Milestone

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.0.0

Minimized code

  ~ scala
scala> class A { def apply(xs: Int*) = 42 }
// defined class A

scala> class B extends A { def apply(xs: Seq[Int]) = 42 }
1 |class B extends A { def apply(xs: Seq[Int]) = 42 }
  |                        ^
  |                        error overriding method apply in class A of type (xs: Seq[Int]): Int;
  |                          method apply of type (xs: Seq[Int]): Int needs `override` modifier

scala> class B extends A { def apply(xs: Seq[Int]) = "42" }
1 |class B extends A { def apply(xs: Seq[Int]) = "42" }
  |                        ^
  |                        error overriding method apply in class A of type (xs: Seq[Int]): Int;
  |                          method apply of type (xs: Seq[Int]): String needs `override` modifier

scala> class B extends A { override def apply(xs: Seq[Int]) = 17 }
// defined class B

scala> B()(42)
1 |B()(42)
  |    ^^
  |    Found:    (42 : Int)
  |    Required: Seq[Int]

scala> (B(): A)(42)
val res0: Int = 17

Output

// TODO add output here

Expectation

Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 16.0.1).
Type in expressions for evaluation. Or try :help.

scala> class A { def apply(xs: Int*) = 42 }
class A

scala> class B extends A { def apply(xs: Seq[Int]) = 42 }
                               ^
       error: name clash between defined and inherited member:
       def apply(xs: Int*): Int in class A and
       def apply(xs: Seq[Int]): Int at line 1
       have same type after erasure: (xs: Seq): Int

scala>

scala/bug#7052

@odersky odersky added the Spree Suitable for a future Spree label Apr 7, 2022
odersky added a commit that referenced this issue Jun 26, 2023
Refchecks runs after elimRepeated and did not
error on an attempt to override RepeatedParam with Seq.

Also show RepeatedParam in error message for double definition.

Fixes #12662

Resubmits #13248 which was opened
against old master.
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug Spree Suitable for a future Spree
Projects
None yet
3 participants