-
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.
Three fixes to SAM type handling (#21596)
The first two fixes concern characterization of SAM types. One condition of a SAM type is that it can be instantiated with an empty argument list. This was implemented incorrectly. First, we missed the case where the SAM type is a trait with a parent class that takes arguments. In this case the SAM type _cannot_ be instantiated with an empty argument list. Second, we missed the case where the SAM type constructor has a single vararg parameter. In this case the SAM type _can_ be instantiated with an empty argument list. The second case was also translated incorrectly which led to illegal bytecodes. Fixes #15855
- Loading branch information
Showing
7 changed files
with
120 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class MyFunction(args: String) | ||
|
||
trait MyFunction0[+R] extends MyFunction { | ||
def apply(): R | ||
} | ||
|
||
def fromFunction0[R](f: Function0[R]): MyFunction0[R] = () => f() // error | ||
|
||
class MyFunctionWithImplicit(implicit args: String) | ||
|
||
trait MyFunction0WithImplicit[+R] extends MyFunctionWithImplicit { | ||
def apply(): R | ||
} | ||
|
||
def fromFunction1[R](f: Function0[R]): MyFunction0WithImplicit[R] = () => f() // error |
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,17 @@ | ||
class MyFunction(args: String*) | ||
|
||
trait MyFunction0[+R] extends MyFunction { | ||
def apply(): R | ||
} | ||
|
||
abstract class MyFunction1[R](args: R*): | ||
def apply(): R | ||
|
||
def fromFunction0[R](f: Function0[R]): MyFunction0[R] = () => f() | ||
def fromFunction1[R](f: Function0[R]): MyFunction1[R] = () => f() | ||
|
||
@main def Test = | ||
val m0: MyFunction0[Int] = fromFunction0(() => 1) | ||
val m1: MyFunction1[Int] = fromFunction1(() => 2) | ||
assert(m0() == 1) | ||
assert(m1() == 2) |