Skip to content

Commit

Permalink
Move bound check from Typer to QuotePatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Aug 7, 2023
1 parent 6764d5e commit 49c0cca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ object QuotePatterns:
def checkPattern(quotePattern: QuotePattern)(using Context): Unit =
val typevars = new tpd.TreeAccumulator[Set[Symbol]] {
override def apply(typevars: Set[Symbol], tree: tpd.Tree)(using Context): Set[Symbol] = tree match {
case _: SplicePattern => typevars
case tree: SplicePattern =>
for typearg <- tree.typeargs
do
if !(typearg.tpe.bounds.lo == defn.AnyType && typearg.tpe.bounds.hi == defn.NothingType) then
report.error(em"Type arguments of hoas patterns should not have bounds")
typevars
case tree @ DefDef(_, paramss, _, _) =>
val newTypevars = paramss.flatMap{ params => params match
case TypeDefs(tdefs) => tdefs.map(_.symbol)
Expand Down
21 changes: 7 additions & 14 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ trait QuotesAndSplices {
def typedSplicePattern(tree: untpd.SplicePattern, pt: Type)(using Context): Tree = {
record("typedSplicePattern")
if isFullyDefined(pt, ForceDegree.flipBottom) then
val typedTypeargs = tree.typeargs.map {
case typearg: untpd.Ident =>
typedType(typearg)
case arg =>
report.error("Open pattern expected an identifier", arg.srcPos)
EmptyTree
}
val typedArgs = withMode(Mode.InQuotePatternHoasArgs) {
tree.args.map {
case arg: untpd.Ident =>
Expand All @@ -119,20 +126,6 @@ trait QuotesAndSplices {
EmptyTree
}
}
val typedTypeargs = tree.typeargs.map {
case typearg: untpd.Ident =>
val typedTypearg = typedType(typearg)
/* TODO-18271: Allow type bounds?
* (NOTE: Needs non-trivial extension to type system)
*/
val bounds = ctx.gadt.fullBounds(typedTypearg.symbol)
if bounds != null && bounds != TypeBounds.empty then
report.error("Type arguments to Open pattern are expected to have no bounds", typearg.srcPos)
typedTypearg
case arg =>
report.error("Open pattern expected an identifier", arg.srcPos)
EmptyTree
}
for arg <- typedArgs if arg.symbol.is(Mutable) do // TODO support these patterns. Possibly using scala.quoted.util.Var
report.error("References to `var`s cannot be used in higher-order pattern", arg.srcPos)
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
Expand Down

0 comments on commit 49c0cca

Please sign in to comment.