-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix generic signature for type params bounded by primitive (#16442)
Fixes #15385
- Loading branch information
Showing
3 changed files
with
55 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Loc(val idx: Int) extends AnyVal | ||
|
||
class Foo: | ||
def testNoParam[A <: Int]: A = 1.asInstanceOf[A] | ||
def testSingleParam[A <: Int](a: A): A = 2.asInstanceOf[A] // <A:Ljava/lang/Object;>(I)I | ||
def testSingleParam2[A <: Int](a: A): Box[A] = new Box[A](a) // <A:Ljava/lang/Object;>(I)LBox<Ljava/lang/Object;>; | ||
def testSingleParam3[A <: Int](box: Box[A]): A = box.value // <A:Ljava/lang/Object;>(LBox<Ljava/lang/Object;>;)I | ||
def testOtherReturn[A <: Int](a: A): String = "3" | ||
def testNoErasure[A <: String](a: A): A = "4".asInstanceOf[A] | ||
def testMultiParam[A <: Int, B <: String](a: A, b: B): A = 5.asInstanceOf[A] | ||
|
||
def testVCNoParam[A <: Loc]: A = Loc(1).asInstanceOf[A] | ||
def testVCSingleParam[A <: Loc](a: A): A = Loc(2).asInstanceOf[A] | ||
def testVCOtherReturn[A <: Loc](a: A): String = "3" | ||
def testVCNoErasure[A <: String](a: A): A = "4".asInstanceOf[A] | ||
def testVCMultiParam[A <: Loc, B <: String](a: A, b: B): A = Loc(5).asInstanceOf[A] | ||
|
||
class Box[T](val value: T) | ||
|
||
class BarParent[X, Y] | ||
trait BarInterface[F, G] | ||
abstract class Bar[A <: Int](a: A) extends BarParent[A, String] with BarInterface[Int, A]: | ||
def getMap: Map[String, A] | ||
def bar[B](a: A, b: B): (A, B, Int) |
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,18 @@ | ||
public class Test { | ||
public static void main(String[] args) throws Exception { | ||
Foo foo = new Foo(); | ||
System.out.println(foo.testNoParam()); | ||
System.out.println(foo.testSingleParam(2)); | ||
System.out.println(foo.testSingleParam2(21).value()); | ||
System.out.println(foo.testSingleParam3(new Box(22))); | ||
System.out.println(foo.testOtherReturn(3)); | ||
System.out.println(foo.testNoErasure("4")); | ||
System.out.println(foo.testMultiParam(5, "5")); | ||
|
||
System.out.println(foo.testVCNoParam()); | ||
System.out.println(foo.testVCSingleParam(2)); | ||
System.out.println(foo.testVCOtherReturn(3)); | ||
System.out.println(foo.testVCNoErasure("4")); | ||
System.out.println(foo.testVCMultiParam(5, "5")); | ||
} | ||
} |