Skip to content
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

Overriding java method returning T[] requires Array[T with Object] / Array[T] with separate/joint compilation respectively #4390

Closed
scabug opened this issue Mar 26, 2011 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Mar 26, 2011

=== What steps will reproduce the problem? ===

 ~/code/scratch/array: cat ArrayFactory.java 
public interface ArrayFactory<T> {
  T[] create(int count);
}

 ~/code/scratch/array: cat ScalaArrayFactory.scala 
class ScalaArrayFactory[T: Manifest] extends ArrayFactory[T] {
  def create(count: Int) = Array.ofDim[T](count)
}

Joint compilation works, separate compilation fails.

 ~/code/scratch/array: scalac -d out ArrayFactory.java ScalaArrayFactory.scala  ~/code/scratch/array: 
 ~/code/scratch/array: javac -d out ArrayFactory.java && scalac -d out -classpath out ScalaArrayFactory.scala 
ScalaArrayFactory.scala:2: error: type mismatch;
 found   : Array[T]
 required: Array[T with java.lang.Object]
  def create(count: Int) = Array.ofDim[T](count)
                                         ^
one error found
Scala compiler version 2.8.1.final -- Copyright 2002-2010, LAMP/EPFL

Same result (although with an expanded error message) result with a snapshot of 2.9 from a few weeks back.

 ~/code/scratch/array: scalac29 -version
Scala compiler version 2.9.0.r24423-b20110309020116 -- Copyright 2002-2011, LAMP/EPFL
 ~/code/scratch/array: javac -d out ArrayFactory.java && scalac29 -d out -classpath out ScalaArrayFactory.scala 
ScalaArrayFactory.scala:2: error: type mismatch;
 found   : Array[T]
 required: Array[T with java.lang.Object]
Note: T >: T with java.lang.Object, but class Array is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: T with java.lang.Object`. (SLS 3.2.10)
  def create(count: Int) = Array.ofDim[T](count)
                                         ^
one error found
 ~/code/scratch/array: scalac29 -d out ArrayFactory.java ScalaArrayFactory.scala 
 ~/code/scratch/array: 

=== What is the expected behavior? ===

Consistent behaviour with joint and separate compilation.

=== What versions of the following are you using? ===

  • Scala: 2.8.1, 2.9.0-SNAPSHOT
@scabug
Copy link
Author

scabug commented Mar 26, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4390?orig=1
Reporter: @retronym

@scabug
Copy link
Author

scabug commented Apr 11, 2011

@odersky said:
(In r24727) Closes #4390, unfortunately by taking the stricter standpoint. No review.

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

2 participants