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

Cannot call an inline method that references a field from an anonymous class created with a transparent inline #16017

Open
arainko opened this issue Sep 11, 2022 · 2 comments

Comments

@arainko
Copy link
Contributor

arainko commented Sep 11, 2022

Compiler version

3.2.0, 3.2.2-RC1-bin-20220909-eaa2889-NIGHTLY

Minimized code

package repro

// this needs to be in a separate file, if placed in the same file then everything works
extension (src: String) {

  // a new anonymous class is essential, it works as expected if this is just a constructor call
  transparent inline def intoViaRepro = new TestClass(src) {} 
}
package repro

class TestClass(source: String) {
  inline def access = source
}

object Repro {
  private val value = "whatever"
  value.intoViaRepro.access
}

Output

[info] exception occurred while compiling ducktape/repro/src/main/scala/Repro.scala, ducktape/repro/src/main/scala/syntax.scala
java.lang.AssertionError: assertion failed: private value value in object Repro in ducktape/repro/src/main/scala/Repro.scala accessed from constructor $anon in ducktape/repro/src/main/scala/syntax.scala while compiling ducktape/repro/src/main/scala/Repro.scala, ducktape/repro/src/main/scala/syntax.scala

Expectation

The code compiles as it did in 3.1.3.

This can be worked around by doing this:

object Repro {
  private val value = "whatever"

  private def workaround(value: String) =
    value.intoViaRepro.access

  workaround(value)
}

Context

I've stumbled upon this error when compiling ducktape with Scala 3.2.0, the file that fails is located here, the class which needs a new anonymus instance here and the extension definition here.

@arainko arainko added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 11, 2022
@soronpo soronpo added regression This worked in a previous version but doesn't anymore area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 11, 2022
@Kordyjan Kordyjan added this to the Future versions milestone Dec 12, 2022
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jan 12, 2023

It seems that this code did not compile in 3.1.3 nor any previous version.

@nicolasstucki nicolasstucki removed the regression This worked in a previous version but doesn't anymore label Jan 12, 2023
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jan 23, 2023

Minimized

transparent inline def intoViaRepro(src: String): TestClass =
  new TestClass(src) {}
class TestClass(val source: String):
  inline def access = source

class Repro(value: String):
  intoViaRepro(value).access

@nicolasstucki nicolasstucki changed the title Cannot call an inline method that references a field from an anonymous class created with a transparent inline extension in 3.2.0 Cannot call an inline method that references a field from an anonymous class created with a transparent inline Jan 23, 2023
@nicolasstucki nicolasstucki removed this from the Future versions milestone Jan 23, 2023
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

5 participants