- 
  Notifications
 You must be signed in to change notification settings 
- Fork 1.1k
java higher-kind interop fails with dotty #16797
-
let's consider the following scala code
trait HigherKind[C[_]]
And java one
public class JHigherKindWrapper { private HigherKind<java.util.List> underlying; }
This used to compile with scala 2.12 and 2.13. With scala 3.2.1, the compiler fails with the following:
[error] | private HigherKind<java.util.List> underlying;
[error] | ^^^^^^^^^^^^^^
[error] |Type argument java.util.List[?] does not have the same kind as its bound [_1ドル]
Why is dotty failing compilation in this case ?
I've setup a minimal project to reproduce here.
Beta Was this translation helpful? Give feedback.
All reactions
Java doesn't have higher-kinded types: while you can write java.util.List without passing type arguments to it, it is equivalent to java.util.List<?> (it's a raw type). When compiling a mixed java/scala project, the Scala compiler also typechecks Java sources, so it will error out on HigkerKind<java.util.List> which it will interpret as the Scala type HigherKind[java.util.List[?]].
I'm not sure why it doesn't happen in Scala 2 though. What's your usecase? If the Scala code doesn't depend on the Java code, you could set up your build tool so the Scala compiler doesn't see the Java code at all (in sbt: compileOrder := CompileOrder.ScalaThenJava)
Replies: 1 comment 1 reply
-
Java doesn't have higher-kinded types: while you can write java.util.List without passing type arguments to it, it is equivalent to java.util.List<?> (it's a raw type). When compiling a mixed java/scala project, the Scala compiler also typechecks Java sources, so it will error out on HigkerKind<java.util.List> which it will interpret as the Scala type HigherKind[java.util.List[?]].
I'm not sure why it doesn't happen in Scala 2 though. What's your usecase? If the Scala code doesn't depend on the Java code, you could set up your build tool so the Scala compiler doesn't see the Java code at all (in sbt: compileOrder := CompileOrder.ScalaThenJava)
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks a lot. Changing the compile order worked!
Beta Was this translation helpful? Give feedback.