forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile quote patterns directly into QuotePattern AST
Fixes scala#14708 Fixes scala#16522 Fixes scala#18125 Fixes scala#18250
- Loading branch information
1 parent
e1e8549
commit f444da9
Showing
13 changed files
with
213 additions
and
301 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
370 changes: 71 additions & 299 deletions
370
compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Large diffs are not rendered by default.
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,7 @@ | ||
-- [E007] Type Mismatch Error: tests/neg-macros/i16522.scala:10:45 ----------------------------------------------------- | ||
10 | case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error | ||
| ^^^^^^^ | ||
| Found: tl | ||
| Required: HList | ||
| | ||
| 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,16 @@ | ||
import scala.quoted.* | ||
|
||
sealed trait HList | ||
case class HCons[+HD, TL <: HList](hd: HD, tl: TL) extends HList | ||
case object HNil extends HList | ||
|
||
def showFirstTwoImpl(e: Expr[HList])(using Quotes): Expr[String] = { | ||
e match { | ||
case '{HCons($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString} | ||
case '{HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error | ||
case '{HCons[hd, HCons[sd, tl]]($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString} | ||
case _ => '{""} | ||
} | ||
} | ||
|
||
transparent inline def showFirstTwo(inline xs: HList) = ${ showFirstTwoImpl('xs) } |
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,10 @@ | ||
import scala.quoted.* | ||
|
||
object Main { | ||
def foo(a: Expr[Any])(using Quotes) = { | ||
a match { | ||
case '{ ($x: Set[t]).toSet } => | ||
case _ => | ||
} | ||
} | ||
} |
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,16 @@ | ||
import scala.quoted.* | ||
|
||
sealed trait HList | ||
case class HCons[+HD, TL <: HList](hd: HD, tl: TL) extends HList | ||
case object HNil extends HList | ||
|
||
def showFirstTwoImpl(e: Expr[HList])(using Quotes): Expr[String] = { | ||
e match { | ||
case '{HCons($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString} | ||
case '{type tl <: HList; HCons($h1: hd1, HCons($h2: hd2, $_ : tl))} => '{$h1.toString ++ $h2.toString} // error | ||
case '{HCons[hd, HCons[sd, tl]]($h1, HCons($h2, $_))} => '{$h1.toString ++ $h2.toString} | ||
case _ => '{""} | ||
} | ||
} | ||
|
||
transparent inline def showFirstTwo(inline xs: HList) = ${ showFirstTwoImpl('xs) } |
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,10 @@ | ||
import scala.quoted.* | ||
|
||
final class Foo[T](ns: T) | ||
|
||
def foo(using Quotes)(x: Expr[Any]): Unit = | ||
x match | ||
case '{ new Foo($y: b) } => | ||
case '{ new Foo($y: List[b]) } => | ||
case '{ type b; new Foo($y: b) } => | ||
|
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,23 @@ | ||
package oolong.phobos | ||
|
||
import scala.quoted.* | ||
import scala.compiletime.* | ||
import scala.annotation.StaticAnnotation | ||
|
||
final class xmlns[T](ns: T) extends StaticAnnotation | ||
trait Namespace[T]{ | ||
val getNamespace: String | ||
} | ||
|
||
object common{ | ||
private def extractFeildNamespace(using Quotes)( | ||
fieldAnnotations: List[Expr[Any]], | ||
): Expr[Option[String]] = { | ||
import quotes.reflect.* | ||
|
||
fieldAnnotations.collect { case '{ xmlns($namespace: b) } => | ||
'{ Some(summonInline[Namespace[b]].getNamespace) } | ||
} | ||
??? | ||
} | ||
} |
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,6 @@ | ||
import scala.quoted.* | ||
|
||
def test(x: Expr[Any])(using Quotes): Unit = | ||
x match | ||
case '{ type t; type u <: t; () } => | ||
case '{ type t <: Comparable[t]; () } => |
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 @@ | ||
import scala.deriving._ | ||
import scala.quoted._ | ||
|
||
private def derivedExpr[T](mirrorExpr: Expr[Mirror.Of[T]])(using Quotes, Type[T]): Expr[Any] = { | ||
mirrorExpr match { | ||
case '{ $mirrorExpr : Mirror.Sum { type MirroredElemTypes = mirroredElemTypes } } => | ||
'{ liftableSum[mirroredElemTypes]($mirrorExpr) } | ||
case '{ type mirroredElemTypes; $mirrorExpr : Mirror.Sum { type MirroredElemTypes = mirroredElemTypes } } => | ||
'{ liftableSum[mirroredElemTypes]($mirrorExpr) } | ||
} | ||
} | ||
|
||
def liftableSum[MElemTypes](mirror: Mirror.Sum { type MirroredElemTypes = MElemTypes }): 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,11 @@ | ||
import scala.deriving._ | ||
import scala.quoted._ | ||
|
||
private def derivedExpr(x: Expr[Any])(using Quotes): Unit = | ||
x match | ||
case '{ type mtp1; ($m1 : Mirror.Sum { type MirroredElemTypes = mtp1 } & Mirror.Of[Any], $m2 : Mirror.Sum { type MirroredElemTypes = mtp2 } & Mirror.Of[Any]); ??? } => | ||
'{ $m1: Mirror.Sum { type MirroredElemTypes = mtp1 } } | ||
'{ $m2: Mirror.Sum { type MirroredElemTypes = mtp2 } } | ||
// ^^^ FIXME | ||
// Found: scala.deriving.Mirror.Sum{type MirroredElemTypes} & scala.deriving.Mirror.Of[Any] | ||
// Required: scala.deriving.Mirror.Sum{type MirroredElemTypes = mtp2} |