-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44713c2
commit 3934cdf
Showing
5 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/tasty/run-pipelined/src-2/tastytest/TestObjectTpeJava.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tastytest | ||
|
||
import lib.ObjectTpeJava | ||
import scala.annotation.nowarn | ||
|
||
// keep in sync with ObjectTpeJava.java | ||
object TestObjectTpeJava extends scala.App { | ||
|
||
val newOTJ = new ObjectTpeJava | ||
|
||
val newOTJInner = new ObjectTpeJava.Inner[Int](23, true) | ||
|
||
newOTJ.meth1(1) // OK | ||
newOTJ.meth2(1) // OK | ||
newOTJ.meth3(List[Int](1)) // OK | ||
newOTJ.meth4(List[Int](1)) // OK | ||
newOTJ.meth5(Array[Object]("abc")) // OK | ||
newOTJ.meth6(Array[String]("abc")) // Ok | ||
// newOTJ.meth5(Array[Int](1)) // error: Array[Int] is not a subtype of Array[Object] | ||
// newOTJ.meth6(Array[Int](1)) // error: Array[Int] is not a subtype of Array[T & Object] | ||
newOTJ.meth7(1) // OK (creates a reference array) | ||
newOTJ.meth8(1) // OK (creates a primitive array and copies it into a reference array at Erasure) | ||
val li = Array[Int](1) | ||
newOTJ.meth7(li: _*) // OK (will copy the array at Erasure) | ||
newOTJ.meth8(li: _*) // OK (will copy the array at Erasure) | ||
|
||
newOTJInner.meth1(1) // OK | ||
newOTJInner.meth2(1) // OK | ||
|
||
assert((newOTJInner.field1: Int) == 23) // OK | ||
newOTJInner.field1 = 31 // OK | ||
assert((newOTJInner.getter1: Int) == 31) // OK | ||
assert(newOTJInner.field2 == true) // OK | ||
newOTJInner.field2 = false // OK | ||
assert(newOTJInner.getter2 == false) // OK | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// this test ensures that Object can accept Any from Scala | ||
// see Definitions.ObjectTpeJava | ||
package lib; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class ObjectTpeJava { | ||
|
||
public static class Inner<T> extends Object { | ||
public T field1; | ||
public T getter1() { return field1; } | ||
public Object field2; | ||
public Object getter2() { return field2; } | ||
|
||
public Inner(T param1, Object param2) { | ||
this.field1 = param1; | ||
this.field2 = param2; | ||
} | ||
|
||
public void meth1(T arg) {} | ||
public <U extends T> void meth2(U arg) {} | ||
} | ||
|
||
// 1. At the top level: | ||
public void meth1(Object arg) {} | ||
public <T> void meth2(T arg) {} // T implicitly extends Object | ||
|
||
// 2. In a class type argument: | ||
public void meth3(scala.collection.immutable.List<Object> arg) {} | ||
public <T> void meth4(scala.collection.immutable.List<T> arg) {} | ||
|
||
// 3. As the type argument of an array: | ||
public void meth5(Object[] arg) {} | ||
public <T> void meth6(T[] arg) {} | ||
|
||
// 4. As the repeated argument of a varargs method: | ||
public void meth7(Object... args) {} | ||
public <T> void meth8(T... args) {} | ||
} |