Skip to content

Unexpected same type after erasure error #5196

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
threeseed opened this issue Jun 10, 2025 · 1 comment
Closed

Unexpected same type after erasure error #5196

threeseed opened this issue Jun 10, 2025 · 1 comment
Labels
as-designed The observed behavior is as-designed, it need not be fixed.

Comments

@threeseed
Copy link

threeseed commented Jun 10, 2025

Code:

import scala.scalajs.js

abstract class A:
  type Props
  def apply(p: Props) = ()

object B extends A:
  case class Props()
  def apply(a: js.UndefOr[String]) = ()

https://scastie.scala-lang.org/wIU34JJtTi2xlNfVldcClg

Error:

Name clash between defined and inherited member:
def apply(p: A.this.Props): Unit in class A at line 7 and
def apply(a: scala.scalajs.js.UndefOr[String]): Unit in object B at line 12
have the same type after erasure.

Consider adding a @targetName annotation to one of the conflicting definitions
for disambiguation

Notes:
The following code works suggesting some issue with js.UndefOr:

import scala.scalajs.js

abstract class A:
  type Props
  def apply(p: Props) = ()

object B extends A:
  case class Props()
  def apply(a: String) = ()

Versions Tested:
3.3.6, 3.7.0.

@sjrd
Copy link
Member

sjrd commented Jun 10, 2025

That's a specified limitation of Scala. You can't have two methods that are overloaded, but that erase to the same type. Props and js.UndefOr both erase to Object, so that's not allowed. It worked with String because it erases to String, not Object.

@sjrd sjrd closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2025
@sjrd sjrd added the as-designed The observed behavior is as-designed, it need not be fixed. label Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as-designed The observed behavior is as-designed, it need not be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants