-
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.
Support polymorphic functions with erased parameters (#18293)
This adds support for ```scala [T1, ..., Tn] => ([erased] x1: X1, ..., [erased] xm: Xm) => r: R ``` Polymorphic function types with erased parameters are represented as using a refinement on `PolyFunction`. `ErasedFunction` is not needed. ```scala PolyFunction { def apply[[T1, ..., Tn]]([given] [erased] x1: X1, ..., [erased] xm: Xm): R } ```
- Loading branch information
Showing
10 changed files
with
95 additions
and
56 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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:3:28 --------------------------------- | ||
3 |def t1a: [T] => T => Unit = [T] => (erased t: T) => () // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: [T] => (erased t: T) => Unit | ||
| Required: [T] => (x$1: T) => Unit | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:4:37 --------------------------------- | ||
4 |def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| Found: [T] => (t: T) => Unit | ||
| Required: [T] => (erased x$1: T) => Unit | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:6:36 --------------------------------- | ||
6 |def t2a: [T, U] => (T, U) => Unit = [T, U] => (t: T, erased u: U) => () // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: [T, U] => (t: T, erased u: U) => Unit | ||
| Required: [T, U] => (x$1: T, x$2: U) => Unit | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:7:43 --------------------------------- | ||
7 |def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: [T, U] => (t: T, u: U) => Unit | ||
| Required: [T, U] => (x$1: T, erased x$2: U) => Unit | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,7 @@ | ||
import language.experimental.erasedDefinitions | ||
|
||
def t1a: [T] => T => Unit = [T] => (erased t: T) => () // error | ||
def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error | ||
|
||
def t2a: [T, U] => (T, U) => Unit = [T, U] => (t: T, erased u: U) => () // error | ||
def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // 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,8 @@ | ||
-- Error: tests/neg/polymorphic-erased-functions-used.scala:3:33 ------------------------------------------------------- | ||
3 |def t1 = [T] => (erased t: T) => t // error | ||
| ^ | ||
| parameter t is declared as `erased`, but is in fact used | ||
-- Error: tests/neg/polymorphic-erased-functions-used.scala:4:42 ------------------------------------------------------- | ||
4 |def t2 = [T, U] => (t: T, erased u: U) => u // error | ||
| ^ | ||
| parameter u is declared as `erased`, but is in fact used |
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,4 @@ | ||
import language.experimental.erasedDefinitions | ||
|
||
def t1 = [T] => (erased t: T) => t // error | ||
def t2 = [T, U] => (t: T, erased u: U) => u // 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,14 @@ | ||
import language.experimental.erasedDefinitions | ||
|
||
object Test: | ||
type T1 = [X] => (erased x: X, y: Int) => Int | ||
type T2 = [X] => (x: X, erased y: Int) => X | ||
|
||
val t1 = [X] => (erased x: X, y: Int) => y | ||
val t2 = [X] => (x: X, erased y: Int) => x | ||
|
||
erased class A | ||
|
||
type T3 = [X] => (x: A, y: X) => X | ||
|
||
val t3 = [X] => (x: A, y: X) => y |
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,22 @@ | ||
import language.experimental.erasedDefinitions | ||
|
||
object Test extends App { | ||
|
||
// Types | ||
type F1 = [T] => (erased T) => Int | ||
type F2 = [T, U] => (T, erased U) => T | ||
|
||
// Terms | ||
val t1 = [T] => (erased t: T) => 3 | ||
assert(t1(List(1, 2, 3)) == 3) | ||
val t1a: F1 = t1 | ||
val t1b: F1 = [T] => (erased t) => 3 | ||
assert(t1b(List(1, 2, 3)) == 3) | ||
|
||
val t2 = [T, U] => (t: T, erased u: U) => t | ||
assert(t2(1, "abc") == 1) | ||
val t2a: F2 = t2 | ||
val t2b: F2 = [T, U] => (t, erased u) => t | ||
assert(t2b(1, "abc") == 1) | ||
|
||
} |