From 49c0cca75b02a44142a2fb06baa244b30a27d638 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 7 Aug 2023 14:20:02 +0900 Subject: [PATCH] Move bound check from Typer to QuotePatterns --- .../tools/dotc/quoted/QuotePatterns.scala | 7 ++++++- .../tools/dotc/typer/QuotesAndSplices.scala | 21 +++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala b/compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala index 66085a21e93c..9c6c6f7f3839 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index e4582434f47d..a4b0d25c7c8a 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -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 => @@ -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)