-
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.
Merge pull request #14425 from dwijnand/quote-matching-avoidance
- Loading branch information
Showing
3 changed files
with
23 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test | ||
|
||
import scala.quoted.* | ||
|
||
object Macro: | ||
def covImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Covariant (List) | ||
case '{ $h : List[h] } => '{ $h : List[h] } | ||
|
||
def invImpl(arg: Expr[Any])(using Quotes): Expr[Any] = arg match // Invariant (Set) | ||
case '{ $h : Set[h] } => '{ $h : Set[h] } | ||
|
||
transparent inline def cov(inline arg: Any): Any = ${ covImpl('arg) } | ||
transparent inline def inv(inline arg: Any): Any = ${ invImpl('arg) } |
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 test | ||
|
||
object Test: | ||
val cov1: List[Boolean] = Macro.cov(List(true)) | ||
val inv1: Set[Boolean] = Macro.inv(Set(true)) | ||
def cov2[X](a: List[X]): List[X] = Macro.cov(a) | ||
def inv2[X](a: Set[X]): Set[X] = Macro.inv(a) // doesn't compile; Set[Nothing] is inferred |