-
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
This adds support for ```scala [T1, ..., Tn] => ([erased] x1: X1, ..., [erased] xm: Xm) => 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]([erased] x1: X1, ..., [erased] xm: Xm): R } ```
- Loading branch information
1 parent
97677cc
commit 2fb1d1f
Showing
8 changed files
with
61 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,8 @@ | ||
-- Error: tests/neg/polymorphic-erased-functions.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.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,15 @@ | ||
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) | ||
|
||
} |