Skip to content

Commit 49c0cca

Browse files
committed
Move bound check from Typer to QuotePatterns
1 parent 6764d5e commit 49c0cca

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ object QuotePatterns:
2929
def checkPattern(quotePattern: QuotePattern)(using Context): Unit =
3030
val typevars = new tpd.TreeAccumulator[Set[Symbol]] {
3131
override def apply(typevars: Set[Symbol], tree: tpd.Tree)(using Context): Set[Symbol] = tree match {
32-
case _: SplicePattern => typevars
32+
case tree: SplicePattern =>
33+
for typearg <- tree.typeargs
34+
do
35+
if !(typearg.tpe.bounds.lo == defn.AnyType && typearg.tpe.bounds.hi == defn.NothingType) then
36+
report.error(em"Type arguments of hoas patterns should not have bounds")
37+
typevars
3338
case tree @ DefDef(_, paramss, _, _) =>
3439
val newTypevars = paramss.flatMap{ params => params match
3540
case TypeDefs(tdefs) => tdefs.map(_.symbol)

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ trait QuotesAndSplices {
110110
def typedSplicePattern(tree: untpd.SplicePattern, pt: Type)(using Context): Tree = {
111111
record("typedSplicePattern")
112112
if isFullyDefined(pt, ForceDegree.flipBottom) then
113+
val typedTypeargs = tree.typeargs.map {
114+
case typearg: untpd.Ident =>
115+
typedType(typearg)
116+
case arg =>
117+
report.error("Open pattern expected an identifier", arg.srcPos)
118+
EmptyTree
119+
}
113120
val typedArgs = withMode(Mode.InQuotePatternHoasArgs) {
114121
tree.args.map {
115122
case arg: untpd.Ident =>
@@ -119,20 +126,6 @@ trait QuotesAndSplices {
119126
EmptyTree
120127
}
121128
}
122-
val typedTypeargs = tree.typeargs.map {
123-
case typearg: untpd.Ident =>
124-
val typedTypearg = typedType(typearg)
125-
/* TODO-18271: Allow type bounds?
126-
* (NOTE: Needs non-trivial extension to type system)
127-
*/
128-
val bounds = ctx.gadt.fullBounds(typedTypearg.symbol)
129-
if bounds != null && bounds != TypeBounds.empty then
130-
report.error("Type arguments to Open pattern are expected to have no bounds", typearg.srcPos)
131-
typedTypearg
132-
case arg =>
133-
report.error("Open pattern expected an identifier", arg.srcPos)
134-
EmptyTree
135-
}
136129
for arg <- typedArgs if arg.symbol.is(Mutable) do // TODO support these patterns. Possibly using scala.quoted.util.Var
137130
report.error("References to `var`s cannot be used in higher-order pattern", arg.srcPos)
138131
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)

0 commit comments

Comments
 (0)