-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Interaction with Java's raw generic types is not possible #3533
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
Reproduced on master with: import javafx.scene.control.TreeTableView
class Test {
def test[T](
table: TreeTableView[T],
callback: javafx.util.Callback[TreeTableView.ResizeFeatures[_], java.lang.Boolean],
): Unit = {
table.setColumnResizePolicy(callback)
}
} -- [E007] Type Mismatch Error: tests/allan/Test.scala:8:32 ---------------------
8 | table.setColumnResizePolicy(callback)
| ^^^^^^^^
|found: javafx.util.Callback[javafx.scene.control.TreeTableView.ResizeFeatures[_],
| Boolean
|](callback)
|required: javafx.util.Callback[javafx.scene.control.TreeTableView.ResizeFeatures, Boolean] |
Note that we cannot import stuff from |
@smarter Here you have an example java class public class TryMe {
public static <R> void ifYouCan(scala.Function1<java.util.List, R> f) {
}
} which when you try to call it from scala you get object RawGenericsTest {
TryMe.ifYouCan(list => println(list))
}
[error] -- [E055] Syntax Error: RawGenericsTest.scala:2:17
error] 2 | TryMe.ifYouCan(list => println(list))
[error] | ^
[error] | missing type parameter for java.util.List or object RawGenericsTest {
TryMe.ifYouCan((list: java.util.List[_]) => println(list))
}
[error] -- [E007] Type Mismatch Error: RawGenericsTest.scala:2:94
[error] 2 | TryMe.ifYouCan((list: java.util.List[_]) => println(list))
[error] | ^
[error] | found: java.util.List[_] => Unit
[error] | required: java.util.List => Unit
[error] |
[error] one error found |
Only the ClassfileParser is fixed (because we can just ask users to fix their Java source files to not use raw types to get them to compile with Dotty). This means that the added Java testcase does not pass Dotty's Java source parser, we handle this by putting "_JAVA_ONLY_" in the filename and skipping files that contain this string from going through Dotty in our testing framework.
Thanks for the simplified testcase! |
Only the ClassfileParser is fixed (because we can just ask users to fix their Java source files to not use raw types to get them to compile with Dotty). This means that the added Java testcase does not pass Dotty's Java source parser, we handle this by putting "JAVA_ONLY" in the filename and skipping files that contain this string from going through Dotty in our testing framework.
Only the ClassfileParser is fixed (because we can just ask users to fix their Java source files to not use raw types to get them to compile with Dotty). This means that the added Java testcase does not pass Dotty's Java source parser, we handle this by putting "JAVA_ONLY" in the filename and skipping files that contain this string from going through Dotty in our testing framework.
Also worth noting, that if you happen to try and compile the java source in mixed mode with dotty (by placing the file under src/main/java), then when dotty parses the java file for the signatures you get this [error] -- Error: TryMe.java:3:72 ------
[error] 3 | public static <R> void ifYouCan(java.util.function.Function<java.util.List, R> f) {
[error] | ^^^^^^^^^^^^^^
[error] | Type argument java.util.List has not the same kind as its bound |
Yes, for now we've decided to not try to make the dotty Java source parser work with raw types since it's usually pretty easy to fix Java code in your own project to not require raw types. We may change this in the future but it's low priority. |
Fix #3533: Fix parsing of raw types appearing in generic position
See for instance Javafx's method https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TreeTableView.html#setColumnResizePolicy-javafx.util.Callback- it takes a
Callback<TreeTableView.ResizeFeatures,Boolean>
but do notice thatResizeFeatures
defines one generic parameter, the method defines a callback that takes it raw though. In scalac, you would pass ajavafx.util.Callback[javafx.scene.control.TreeTableView.ResizeFeatures[_], Boolean]
and it would typecheck, but with dottyc it doesn't workThe text was updated successfully, but these errors were encountered: