-
Notifications
You must be signed in to change notification settings - Fork 1.1k
No generic signature emitted for trait getter #6350
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
Comments
The lack of generic signature for trait getters leads to the following warning when compiling > dotty-sbt-bridge/compile
[info] Updating dotty-sbt-bridge...
[info] Done updating.
[info] Compiling 9 Java sources to /home/smarter/opt/dotty/sbt-bridge/src/target/classes ...
[warn] /home/smarter/opt/dotty/sbt-bridge/src/xsbt/DelegatingReporter.java:24:1: dotty$tools$dotc$reporting$UniqueMessagePositions$$positions() in dotty.tools.dotc.reporting.AbstractReporter implements dotty$tools$dotc$reporting$UniqueMessagePositions$$positions() in dotty.tools.dotc.reporting.UniqueMessagePositions
[warn] return type requires unchecked conversion from scala.collection.mutable.HashMap to scala.collection.mutable.HashMap<scala.Tuple2<dotty.tools.dotc.util.SourceFile,java.lang.Object>,java.lang.Object>
[warn] final public class DelegatingReporter extends AbstractReporter {
[info] Done compiling. |
Note that the mixin in scalac is somewhat of a mess, precisely because there is no good time to do it. So we should step very carefully before trying to copy things. |
This also shows up in Akka. Looking at the bytecode, the trait getter, setter and also the field are lacking signatures. trait L[+T]
trait T { private var transitionEvent: L[String] = ??? }
class C extends T public class Test extends C { }
Mixin got a good overhaul for 2.12 in scala/scala#5141 (and, I guess, some follw-ups). |
Here is a minimization of the warning mentioned by @smarter (and taken from Source file // minimized from compiler/src/dotty/tools/dotc/reporting/Reporter.scala
abstract class Reporter // extends interfaces.ReporterResult Source file // minimized from compiler/src/dotty/tools/dotc/reporting/UniqueMessagePositions.scala
import scala.collection.mutable
trait UniqueMessagePositions extends Reporter {
private val positions = new mutable.HashMap[(/*SourceFile*/String, Int), Int]
} Source file // minimized from compiler/src/dotty/tools/dotc/reporting/AbstractReporter.scala
abstract class AbstractReporter extends Reporter with UniqueMessagePositions Java source file // minimized from sbt-bridge/src/dotty/tools/xsbt/DelegatingReporter.java
final public class DelegatingReporter extends AbstractReporter {
} 2-steps compilation (Java 1.8.0u302 and Scala 3.0.2-RC2 on Windows):
Output :
|
Is this still an issue after we changed the mixin scheme? |
Yes, this issue is still present. |
It's possible we could fix this just by emitting the getter/setter in the subclasses with ACC_SYNTHETIC (in my initial comment I mentioned emitting methods as bridges but I was confused: the only flag javac cares about is ACC_SYNTHETIC which we can emit on any method). However, using ACC_SYNTHETIC when implementing trait methods can lead to other issues as tracked in #13104 |
Given:
Decompiling with cfr shows:
Notice the lack of generic signature on
bla()
inBar
, since trait getters are emitted inMixin
after erasure, getting a generic signature is not trivial. For mixin forwarders we work around this by emitting them as bridges (cf 6d0f9ca), but we should probably not do that for trait setters since they are not legitimately bridges.We could also try to move trait getter (and setter, and maybe more stuff) before erasure since that's what scalac appear to be doing.
The text was updated successfully, but these errors were encountered: