Open
Description
Given:
class A {
def foo: String = synchronized {
""
}
}
Dotty generates the equivalent of:
public String foo() {
String string;
A a = this;
synchronized (a) {
string = "";
}
return string;
}
whereas Scala 2 generates something equivalent to:
public synchronized String foo() {
return "";
}
which at the very least requires less bytecode. This is implemented by translateSynchronized
in https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/transform/UnCurry.scala, but one has to be careful about not emitting synchronized static methods: scala/bug#11331 scala/scala#7593 scala/scala#7749