scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

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

Open mkurz opened this issue 2 years ago • 5 comments

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 https://github.com/playframework/playframework/issues/12272

mkurz avatar Dec 14 '23 11:12 mkurz

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

  • #19276

?

mkurz avatar Dec 15 '23 14:12 mkurz

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.

dwijnand avatar Dec 18 '23 10:12 dwijnand

@dwijnand Is this still on someones list?

987Nabil avatar Mar 13 '24 16:03 987Nabil

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.

gaeljw avatar Oct 02 '24 16:10 gaeljw

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

Gedochao avatar Oct 17 '24 12:10 Gedochao

Hi, I have come across a similar issue with Scala 3 and the latest EE glassfish jersey rest framework 2.x as used in project code using JAXRS annotations in trait methods. The Jersey code is ignoring methods with Method modifier Synthetic in a change it made for Kotlin some years back related to locating JAXRS annotating methods (used to serve HTTP rest requests). The project code we have is fine user Scala 2.13 but not with Scala 3. Can anyone comment on the fix here as to whether it should work for this case too or is there an additional effort needed? (I did look at code changes and tests but wasn't clear to me.)

ecrabor8 avatar Feb 23 '25 20:02 ecrabor8

Hi, I have come across a similar issue with Scala 3 and the latest EE glassfish jersey rest framework 2.x as used in project code using JAXRS annotations in trait methods. The Jersey code is ignoring methods with Method modifier Synthetic in a change it made for Kotlin some years back related to locating JAXRS annotating methods (used to serve HTTP rest requests). The project code we have is fine user Scala 2.13 but not with Scala 3. Can anyone comment on the fix here as to whether it should work for this case too or is there an additional effort needed? (I did look at code changes and tests but wasn't clear to me.)

Not sure if we have enough data to answer your question, but I'll still tag @sjrd @hamzaremmal

Gedochao avatar Feb 24 '25 08:02 Gedochao

The PR is supposed to do everything like Scala 2.13, so if it works on 2.13, I expect it will work with that PR.

sjrd avatar Feb 24 '25 08:02 sjrd

Hi Sebastien, Thanks for the quick reply. The issue with this one took me several days into glassfish Jersey code before i finally found how it worked. I had seen that by adding wrapper method in the child class/object with jaxrs annotations there that forwarded to the parent trait implementation had worked around the issue. Our problem is we have hundreds of methods with the Jaxrx annotations in traits. This is blocking us from upgrading to Scala 3. note -- yet to consider moving from Jersey to say Resteasy. So, if you know when this may merge into Dotty and then into Scala 3 it would be appreciated. We should up the priority of it, IMHO. thanks Craig

On Mon, Feb 24, 2025 at 3:57 AM Sébastien Doeraene @.***> wrote:

The PR is supposed to do everything like Scala 2.13, so if it works on 2.13, I expect it will work with that PR.

— Reply to this email directly, view it on GitHub https://github.com/scala/scala3/issues/19270#issuecomment-2677775658, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD2AFA3HLXNA4VZOPZCXQD2RLNGLAVCNFSM6AAAAABPICPXLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZXG43TKNRVHA . You are receiving this because you commented.Message ID: @.***> [image: sjrd]sjrd left a comment (scala/scala3#19270) https://github.com/scala/scala3/issues/19270#issuecomment-2677775658

The PR is supposed to do everything like Scala 2.13, so if it works on 2.13, I expect it will work with that PR.

— Reply to this email directly, view it on GitHub https://github.com/scala/scala3/issues/19270#issuecomment-2677775658, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD2AFA3HLXNA4VZOPZCXQD2RLNGLAVCNFSM6AAAAABPICPXLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZXG43TKNRVHA . You are receiving this because you commented.Message ID: @.***>

ecrabor8 avatar Feb 24 '25 12:02 ecrabor8

hi, Here is a link to change that glassfish Jersey code made regarding ignoring synthetic attributed method: https://github.com/eclipse-ee4j/jersey/pull/4112/files

On Mon, Feb 24, 2025 at 7:32 AM craig bordelon @.***> wrote:

Hi Sebastien, Thanks for the quick reply. The issue with this one took me several days into glassfish Jersey code before i finally found how it worked. I had seen that by adding wrapper method in the child class/object with jaxrs annotations there that forwarded to the parent trait implementation had worked around the issue. Our problem is we have hundreds of methods with the Jaxrx annotations in traits. This is blocking us from upgrading to Scala 3. note -- yet to consider moving from Jersey to say Resteasy. So, if you know when this may merge into Dotty and then into Scala 3 it would be appreciated. We should up the priority of it, IMHO. thanks Craig

On Mon, Feb 24, 2025 at 3:57 AM Sébastien Doeraene < @.***> wrote:

The PR is supposed to do everything like Scala 2.13, so if it works on 2.13, I expect it will work with that PR.

— Reply to this email directly, view it on GitHub https://github.com/scala/scala3/issues/19270#issuecomment-2677775658, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD2AFA3HLXNA4VZOPZCXQD2RLNGLAVCNFSM6AAAAABPICPXLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZXG43TKNRVHA . You are receiving this because you commented.Message ID: @.***> [image: sjrd]sjrd left a comment (scala/scala3#19270) https://github.com/scala/scala3/issues/19270#issuecomment-2677775658

The PR is supposed to do everything like Scala 2.13, so if it works on 2.13, I expect it will work with that PR.

— Reply to this email directly, view it on GitHub https://github.com/scala/scala3/issues/19270#issuecomment-2677775658, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD2AFA3HLXNA4VZOPZCXQD2RLNGLAVCNFSM6AAAAABPICPXLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNZXG43TKNRVHA . You are receiving this because you commented.Message ID: @.***>

ecrabor8 avatar Feb 24 '25 12:02 ecrabor8

Can you please re-open? Fix got reverted by #23613

mkurz avatar Jul 29 '25 14:07 mkurz

@WojciechMazur just FYI, we'll need another fix for this in 3.8.0, it seems we won't be able to backport it to 3.7.3 after all.

Gedochao avatar Aug 04 '25 12:08 Gedochao