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

TASTy reader: Accessing opaque type with type param causes NoSuchMethodError #13072

Open
jilen opened this issue Dec 20, 2024 · 5 comments
Open
Milestone

Comments

@jilen
Copy link

jilen commented Dec 20, 2024

Compiler version

3.5.2 and other versions

Minimized code

https://github.com/jilen/scala2-opaque-error

file1 define opaque type (scala3)

object Alias {
  opaque type Of[X] <: X = X

  def of[X](i: X): Alias.Of[X] = i
}
class Foo(id: Alias.Of[Long])

file2, use opaque type (scala 2.13)

object FooApp {
  def main(args: Array[String]) = {
    val f = new Foo(Alias.of(1L))
    println(f)
  }
}

Output

Compiles fine, run fail with

[113] Exception in thread "main" java.lang.NoSuchMethodError: 'void lib.Foo.<init>(java.lang.Object)'
[113] apat app.FooApp$.main(App.scala:8)
[113] 13at app.FooApp.main(App.scala)

Expectation

Should run without exception

@jilen jilen changed the title Use opaque type with type param in scala 2.13 result in NoSuchMethodError Use opaque type with type param in scala 2.13 result in runtime NoSuchMethodError Dec 20, 2024
@SethTisue
Copy link
Member

SethTisue commented Dec 21, 2024

Did you enable -Ytasty-reader? I don't recall offhand if opaque types are in the supported subset of Scala 3.

@jilen
Copy link
Author

jilen commented Dec 22, 2024

@SethTisue There's a repo with github action to demo the error.
https://github.com/jilen/scala2-opaque-error/actions/runs/12455416725/job/34767789185#step:4:27

@SethTisue
Copy link
Member

@bishabosha is this a bug, or expected behavior?

@bishabosha
Copy link
Member

I wrote it such that it is replaced with its rhs at erasure - I might not have considered substitutions

@SethTisue SethTisue transferred this issue from scala/scala3 Dec 22, 2024
@SethTisue SethTisue added this to the 2.13.17 milestone Dec 22, 2024
@SethTisue
Copy link
Member

transferred to scala/bug since it seems likely the issue is on the Scala 2 side

@SethTisue SethTisue changed the title Use opaque type with type param in scala 2.13 result in runtime NoSuchMethodError TASTy reader: Accessing opaque type with type param causes NoSuchMethodError Dec 22, 2024
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