forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIP-53 - Quote pattern explicit type variable syntax (scala#17362)
SIP-53: https://github.com/scala/improvement-proposals/blob/main/content/quote-pattern-type-variable-syntax.md This PR implements the feature under experimental mode.
- Loading branch information
Showing
19 changed files
with
353 additions
and
39 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
9 changes: 9 additions & 0 deletions
9
tests/neg-custom-args/no-experimental/sip-53-exprimental-a.scala
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,9 @@ | ||
import scala.quoted.* | ||
|
||
def foo(using Quotes): Unit = | ||
(??? : Type[?]) match | ||
case '[ (t, t, t) ] => // error // error | ||
'{ ??? : Any } match | ||
case '{ type u; $x: u } => // error | ||
case '{ type u; ($ls: List[u]).map($f: u => Int) } => // error // error | ||
|
8 changes: 8 additions & 0 deletions
8
tests/neg-custom-args/no-experimental/sip-53-exprimental-b.scala
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 @@ | ||
import scala.quoted.* | ||
|
||
def empty[K <: AnyKind : Type](using Quotes): Type[?] = | ||
Type.of[K] match | ||
case '[type t; `t`] => Type.of[t] // error | ||
case '[type f[X]; `f`] => Type.of[f] // error | ||
case '[type f[X <: Int, Y]; `f`] => Type.of[f] // error | ||
case '[type k <: AnyKind; `k` ] => Type.of[k] // 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,22 @@ | ||
import scala.quoted.* | ||
def types(t: Type[?])(using Quotes) = t match { | ||
case '[ type t; Int ] => | ||
case '[ type t <: Int; Int ] => | ||
case '[ type t >: 1 <: Int; Int ] => | ||
case '[ type t = Int; Int ] => // error | ||
case '[ type t = scala.Int; Int ] => // error | ||
case '[ type f[t] <: List[Any]; Int ] => | ||
case '[ type f[t <: Int] <: List[Any]; Int ] => | ||
case '[ type f[t] = List[Any]; Int ] => // error | ||
} | ||
|
||
def expressions(x: Expr[Any])(using Quotes) = x match { | ||
case '{ type t; () } => | ||
case '{ type t <: Int; () } => | ||
case '{ type t >: 1 <: Int; () } => | ||
case '{ type t = Int; () } => // error | ||
case '{ type t = scala.Int; () } => // error | ||
case '{ type f[t] <: List[Any]; () } => | ||
case '{ type f[t <: Int] <: List[Any]; () } => | ||
case '{ type f[t] = List[Any]; () } => // 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,12 @@ | ||
-- Warning: tests/neg-macros/quote-type-variable-no-inference.scala:5:17 ----------------------------------------------- | ||
5 | case '[ F[t, t] ] => // warn // error | ||
| ^ | ||
| Ignored bound <: Double | ||
| | ||
| Consider defining bounds explicitly `'{ type t <: Int & Double; ... }` | ||
-- [E057] Type Mismatch Error: tests/neg-macros/quote-type-variable-no-inference.scala:5:15 ---------------------------- | ||
5 | case '[ F[t, t] ] => // warn // error | ||
| ^ | ||
| Type argument t does not conform to upper bound Double | ||
| | ||
| 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,8 @@ | ||
import scala.quoted.* | ||
|
||
def test(x: Type[?])(using Quotes) = | ||
x match | ||
case '[ F[t, t] ] => // warn // error | ||
case '[ type u <: Int & Double; F[u, u] ] => | ||
|
||
type F[x <: Int, y <: Double] |
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
Oops, something went wrong.