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

Wrong bridge clash error #10150

Closed
scabug opened this issue Jan 16, 2017 · 4 comments
Closed

Wrong bridge clash error #10150

scabug opened this issue Jan 16, 2017 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jan 16, 2017

Compiling

class Arr[T](private val underlying: scala.Array[T]) extends AnyVal

trait SeqMonoTransforms[+A, +Repr] extends Any {
  protected[this] def fromIterableWithSameElemType(): Repr
}

class ArrOps[A](val xs: Arr[A]) extends AnyRef with SeqMonoTransforms[A, Arr[A]] {
  def fromIterableWithSameElemType(): Arr[A] = xs
}

object Test {
  def main(args: Array[String]) =
    println(new ArrOps(new Arr(Array(1, 2, 3))).fromIterableWithSameElemType)
}

we get:

iarray.scala:10: error: bridge generated for member method fromIterableWithSameElemType: ()Arr[A] in class ArrOps
which overrides method fromIterableWithSameElemType: ()Repr in trait SeqMonoTransforms
clashes with definition of the member itself;
both have erased type ()Object
  def fromIterableWithSameElemType(): Arr[A] = xs
      ^

The error makes no sense. No bridge should have been generated, as the erasures of both fromIterableWithSameElemType methods have the same type ()Object

This is a blocker for any attempt to add immutable arrays to the collection strawman.

@scabug
Copy link
Author

scabug commented Jan 16, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10150?orig=1
Reporter: @odersky

@scabug
Copy link
Author

scabug commented Jan 16, 2017

@odersky said:
See dotty scala/scala3#1906 for a fix.

@scabug
Copy link
Author

scabug commented Jan 16, 2017

@DarkDimius said (edited on Jan 16, 2017 9:26:21 AM UTC):

as the erasures of both fromIterableWithSameElemType methods have the same type ()Object

Though erasure of both method is the same, the returned Object should have different type: Repr is SeqMonoTransforms and A in ArrOps. I don't think this error is spurios or wrong: under current compilation scheme for value classes we can't indeed correctly compile this class. More details(and a proposed solution that breaks binary compatibility) in my comments in scala/scala3#1905

@scabug
Copy link
Author

scabug commented Jan 16, 2017

@retronym said:
Closing to consolidate the discussion at scala/scala3#1905

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

No branches or pull requests

2 participants