Skip to content
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

Bridge method clash with value class #8001

Open
travisbrown opened this issue Jan 15, 2020 · 6 comments
Open

Bridge method clash with value class #8001

travisbrown opened this issue Jan 15, 2020 · 6 comments

Comments

@travisbrown
Copy link
Contributor

@travisbrown travisbrown commented Jan 15, 2020

minimized code

trait TC[A] {
  def apply(a: A): Unit
}

class Foo[A](val value: A) extends AnyVal
object Foo {
  val tc = new TC[Foo[String]] {
    def apply(a: Foo[String]): Unit = ()
  }
}
Compilation output
-- Error: TC.scala:8:8 ---------------------------------------------------------
8 |    def apply(a: Foo[String]): Unit = ()
  |        ^
  |bridge generated for member method apply(a: Foo[String]): Unit in anonymous class Object with TC {...}
  |which overrides method apply(a: A): Unit in trait TC
  |clashes with definition of the member itself; both have erased type (a: Object): Unit."
1 error found

expectation

Another minimization from the Cats tests. Scala 2 is fine with this.

@odersky

This comment has been minimized.

Copy link
Contributor

@odersky odersky commented Jan 15, 2020

There's a long history about this bug which is really a shortcoming of the value class encoding. Given that value classes are not pursued further, and the bug would likely cost a person several weeks to fix, I am not sure we will ever fix it. I do hope there is a workaround.

@travisbrown

This comment has been minimized.

Copy link
Contributor Author

@travisbrown travisbrown commented Jan 15, 2020

@odersky We can easily work around this, thanks.

@odersky

This comment has been minimized.

Copy link
Contributor

@odersky odersky commented Jan 16, 2020

@travisbrown Good to know, thanks!

@smarter smarter self-assigned this Jan 18, 2020
@travisbrown travisbrown mentioned this issue Jan 24, 2020
4 of 12 tasks complete
@bishabosha

This comment has been minimized.

Copy link
Member

@bishabosha bishabosha commented Feb 1, 2020

minimise to this

case class Box(a: Any) extends AnyVal

or perhaps this to avoid case:

class Box(a: Any) extends AnyVal
object Box extends (Any => Box)
  def apply(a: Any): Box = new Box(a)
@Jasper-M

This comment has been minimized.

Copy link
Contributor

@Jasper-M Jasper-M commented Feb 4, 2020

@bishabosha The code that Travis posted compiles fine in Scala 2, while yours will error in Scala 2 as well.

I think the bug (or just difference from scala 2, don't know...) here is that dotc thinks that Foo[String] or Foo[Int] erase to Object instead of String or Int respectively.

@smarter

This comment has been minimized.

Copy link
Member

@smarter smarter commented Feb 4, 2020

I think the bug (or just difference from scala 2, don't know...) here is that dotc thinks that Foo[String] or Foo[Int] erase to Object instead of String or Int respectively.

Yes, exactly. I'm working on a fix.

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.