bug icon indicating copy to clipboard operation
bug copied to clipboard

TASTy reader: Accessing opaque type with type param causes `NoSuchMethodError`

Open jilen opened this issue 1 year ago • 5 comments

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 avatar Dec 20 '24 09:12 jilen

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

SethTisue avatar Dec 21 '24 15:12 SethTisue

@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

jilen avatar Dec 22 '24 15:12 jilen

@bishabosha is this a bug, or expected behavior?

SethTisue avatar Dec 22 '24 15:12 SethTisue

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

bishabosha avatar Dec 22 '24 15:12 bishabosha

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

SethTisue avatar Dec 22 '24 16:12 SethTisue