-
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 #7139: Implement kind-projector compatibility
This change adds support for a subset of kind-projector's syntax behind the existing -Ykind-projector flag. It supports the following kind-projector features: - * placeholder (Functor[F[L, *]] instead of Functor[[x] => F[L, x]]). - * in tuple types (Functor[(A, *)] instead of Functor[[x] => (A, x)]). - * in function types (both Functor[S => *] and Functor[* => T] work). - λ syntax (Functor[λ[x => (x, x)]] for Functor[[x] => (x, x)]). There are a few things kind-projector provides that the flag doesn't: - ? as a placeholder (since it collides with wildcards). - * as a placeholder in infix types. - Lambda as an alternative for λ. - λ arguments of a kind other than * (no λ[f[_] => Functor[f]]). - Variance annotations on either * or λ arguments. - Polymorphic lambda values (λ[Vector ~> List](_.toList)). The changes have no effect on parsing if -Ykind-projector isn't enabled.
- Loading branch information
1 parent
899c59b
commit b5adfcb
Showing
6 changed files
with
115 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Error: tests/neg-custom-args/kind-projector.scala:7:23 -------------------------------------------------------------- | ||
7 |class Bar3 extends Foo[λ[List[x] => Int]] // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| λ requires a single argument of the form X => ... or (X, Y) => ... | ||
-- Error: tests/neg-custom-args/kind-projector.scala:5:23 -------------------------------------------------------------- | ||
5 |class Bar1 extends Foo[Either[*, *]] // error | ||
| ^^^^^^^^^^^^ | ||
| Type argument Either has not the same kind as its bound <: [_$1] => Any | ||
-- Error: tests/neg-custom-args/kind-projector.scala:6:22 -------------------------------------------------------------- | ||
6 |class Bar2 extends Foo[*] // error | ||
| ^ | ||
| Type argument _$4 has not the same kind as its bound <: [_$1] => Any |
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 @@ | ||
package kind_projector_neg | ||
|
||
trait Foo[F[_]] | ||
|
||
class Bar1 extends Foo[Either[*, *]] // error | ||
class Bar2 extends Foo[*] // error | ||
class Bar3 extends Foo[λ[List[x] => Int]] // 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 @@ | ||
package kind_projector | ||
|
||
trait Foo[F[_]] | ||
trait Qux[F[_, _]] | ||
trait Baz[F[_], A, B] | ||
|
||
class Bar1 extends Foo[Either[Int, *]] | ||
class Bar2 extends Foo[Either[*, Int]] | ||
class Bar3 extends Foo[* => Int] | ||
class Bar4 extends Foo[Int => *] | ||
class Bar5 extends Foo[(Int, *, Int)] | ||
class Bar6 extends Foo[λ[x => Either[Int, x]]] | ||
class Bar7 extends Qux[λ[(x, y) => Either[y, x]]] | ||
class Bar8 extends Foo[Baz[Int => *, *, Int]] | ||
class Bar9 extends Foo[λ[x => Baz[x => *, Int, x]]] |