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

Scala 3.3.1: Concrete method inside trait marked (incorrectly?) as ACC_BRIDGE and ACC_SYNTHETIC #19270

Open
mkurz opened this issue Dec 14, 2023 · 5 comments · May be fixed by #21890
Open

Scala 3.3.1: Concrete method inside trait marked (incorrectly?) as ACC_BRIDGE and ACC_SYNTHETIC #19270

mkurz opened this issue Dec 14, 2023 · 5 comments · May be fixed by #21890

Comments

@mkurz
Copy link
Contributor

mkurz commented Dec 14, 2023

Compiler version

3.3.1

Reproducer

(Sorry I don't have time to come up with a minimized code example)

git clone [email protected]:mkurz/play-samples.git
cd play-samples/play-scala-hello-world-tutorial
git checkout issue-12272
sbt run

# In another terminal (or use a browser)
curl localhost:9000

You will see the Play app fails with an exception.
However the exact same application works just fine with Scala 2.13.12 (++2.x ; run).

Description why the problem occurs:
Our controller class extends from the InjectedController trait (line):

class HomeController @Inject()() extends InjectedController {

The InjectedController trait defines a concrete method setControllerComponents which should get components injected by Guice (line)

  @Inject
  def setControllerComponents(components: ControllerComponents): Unit = {
    _components = components
  }

Problem: In Scala 2 Guice does inject components and calls the method, in Scala 3 it does not.

When decompiling HomeController.class (using javap -v) the method signature for setControllerComponents is different for Scala 2.13 and Scala 3.

Scala 2.13:

  public void setControllerComponents(play.api.mvc.ControllerComponents);
    descriptor: (Lplay/api/mvc/ControllerComponents;)V
    flags: (0x0001) ACC_PUBLIC

Scala 3:

  public void setControllerComponents(play.api.mvc.ControllerComponents);
    descriptor: (Lplay/api/mvc/ControllerComponents;)V
    flags: (0x1041) ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC

So you see Scala 3 marks the method as synthetic bridge method (ACC_BRIDGE and ACC_SYNTHETIC).

Guice however ignores such methods:
https://github.com/google/guice/blob/f095cad8aa7b59abafacc4d4461ddfc77be83667/core/src/com/google/inject/spi/InjectionPoint.java#L819-L841

The question I have is: Why is that concrete method marked as ACC_BRIDGE and ACC_SYNTHETIC in Scala 3? Is that a bug? If not, how can I make our code work? Are there any docs or notes on that behaviour?

Thanks!

Originally posted by @ThomasGrt in playframework/playframework#12272

@mkurz
Copy link
Contributor Author

mkurz commented Dec 15, 2023

If that is a bug in Scala, is there a chance a fix still makes it into 3.3.2-RC1, as I see there is

?

@dwijnand dwijnand added area:transform and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 18, 2023
@dwijnand
Copy link
Member

Why is that concrete method marked as ACC_BRIDGE and ACC_SYNTHETIC in Scala 3?

setControllerComponents being a trait method that sets instance state, it needs special handling to compile to classfiles. But hopefully we can make this use case work.

If that is a bug in Scala, is there a chance a fix still makes it into 3.3.2-RC1

I don't we have someone to work on this in the next 2 days. It's not high impacting nor a regression within 3.3.x.

@987Nabil
Copy link

@dwijnand Is this still on someones list?

@sjrd sjrd self-assigned this Mar 13, 2024
@gaeljw
Copy link

gaeljw commented Oct 2, 2024

Any update on this issue? While not critical AFAIK, it's still something that many users hit with Play Framework when migrating from Scala 2.13 to 3.x. Play being one of the main Scala frameworks I believe.

@Gedochao
Copy link
Contributor

@gaeljw no updates, but I'll try to get someone on it soon.

@dwijnand dwijnand self-assigned this Oct 18, 2024
@dwijnand dwijnand removed their assignment Nov 4, 2024
sjrd added a commit to dotty-staging/dotty that referenced this issue Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants