Skip to content

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

Closed
rcano opened this issue Nov 22, 2017 · 6 comments
Closed

Interaction with Java's raw generic types is not possible #3533

rcano opened this issue Nov 22, 2017 · 6 comments

Comments

@rcano
Copy link

rcano commented Nov 22, 2017

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 that ResizeFeatures defines one generic parameter, the method defines a callback that takes it raw though. In scalac, you would pass a javafx.util.Callback[javafx.scene.control.TreeTableView.ResizeFeatures[_], Boolean] and it would typecheck, but with dottyc it doesn't work

@allanrenucci
Copy link
Contributor

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]

@smarter
Copy link
Member

smarter commented Jan 4, 2018

Note that we cannot import stuff from javafx in our testsuite: it is not part of the standard builds of openjdk and can be quite cumbersome to manually install.

@rcano
Copy link
Author

rcano commented Jan 4, 2018

@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

smarter added a commit to dotty-staging/dotty that referenced this issue Jan 4, 2018
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.
@smarter
Copy link
Member

smarter commented Jan 4, 2018

Thanks for the simplified testcase!

smarter added a commit to dotty-staging/dotty that referenced this issue Jan 4, 2018
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.
smarter added a commit to dotty-staging/dotty that referenced this issue Jan 4, 2018
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.
@rcano
Copy link
Author

rcano commented Jan 5, 2018

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 

@smarter
Copy link
Member

smarter commented Jan 5, 2018

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.

@smarter smarter closed this as completed in d19a792 Jan 8, 2018
smarter added a commit that referenced this issue Jan 8, 2018
Fix #3533: Fix parsing of raw types appearing in generic position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants