Skip to content

Bridge generation error for AnyVal classes #14009

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
Atry opened this issue Nov 27, 2021 · 2 comments
Closed

Bridge generation error for AnyVal classes #14009

Atry opened this issue Nov 27, 2021 · 2 comments
Assignees

Comments

@Atry
Copy link
Contributor

Atry commented Nov 27, 2021

Compiler version

3.1.0

Minimized code

class Nullable[A](val value: A | Null) extends AnyVal

def f[A] = {
  new (Nullable[A] => A | Null) {
    def apply(nullable: Nullable[A]) = nullable.value
  }
}

Output

bridge generated for member method apply(nullable: Playground.Nullable[A]): A | Null in anonymous class Object with Function1 {...}
which overrides method apply(v1: T1): R in trait Function1
clashes with definition of the member itself; both have erased type (nullable: Object): Object."

Expectation

It should compile

@noti0na1
Copy link
Member

The issue is not related to explicit nulls. The same error can be triggered without the | Null:

class C[A](val value: A) extends AnyVal

class F[A] extends (C[A] => A):
  def apply(x: C[A]) = x.value
    |  def apply(x: C[A]) = x.value
    |      ^
    |bridge generated for member method apply(x: C[A]): A in class F
    |which overrides method apply(v1: T1): R in trait Function1
    |clashes with definition of the member itself; both have erased type (x: Object): Object."

@odersky @smarter Is this related to #1905 and #7023?

@noti0na1 noti0na1 changed the title Bridge generation error for explicit nulls in an AnyVal Bridge generation error for AnyVal classes Jan 17, 2022
@smarter
Copy link
Member

smarter commented Jan 17, 2022

Yes this is the same as #1905 which is an unfixable limitaiton of value classes (at least until valhalla lands), so closing as won't fix unfortunately.

@smarter smarter closed this as completed Jan 17, 2022
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

3 participants