Skip to content

Commit e469bc5

Browse files
committed
Add a new mode InQuotePatternHoasArgs
1 parent 76d2862 commit e469bc5

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ object Mode {
4444
/** Are we looking for cyclic references? */
4545
val CheckCyclic: Mode = newMode(5, "CheckCyclic")
4646

47+
val InQuotePatternHoasArgs: Mode = newMode(6, "InQuotePatternHoasArgs")
48+
4749
/** We are in a pattern alternative */
4850
val InPatternAlternative: Mode = newMode(7, "InPatternAlternative")
4951

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ trait QuotesAndSplices {
107107
if isFullyDefined(pt, ForceDegree.flipBottom) then
108108
def patternOuterContext(ctx: Context): Context =
109109
if (ctx.mode.is(Mode.QuotedPattern)) patternOuterContext(ctx.outer) else ctx
110-
val typedArgs = tree.args.map {
111-
case arg: untpd.Ident =>
112-
withoutMode(Mode.ImplicitsEnabled)(typedExpr(arg))
113-
case arg =>
114-
report.error("Open pattern expected an identifier", arg.srcPos)
115-
EmptyTree
110+
val typedArgs = withMode(Mode.InQuotePatternHoasArgs) {
111+
tree.args.map {
112+
case arg: untpd.Ident =>
113+
typedExpr(arg)
114+
case arg =>
115+
report.error("Open pattern expected an identifier", arg.srcPos)
116+
EmptyTree
117+
}
116118
}
117119
for arg <- typedArgs if arg.symbol.is(Mutable) do // TODO support these patterns. Possibly using scala.quoted.util.Var
118120
report.error("References to `var`s cannot be used in higher-order pattern", arg.srcPos)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,9 +4058,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40584058
wtp match {
40594059
case wtp: ExprType =>
40604060
readaptSimplified(tree.withType(wtp.resultType))
4061-
case wtp: MethodType if wtp.isImplicitMethod &&
4062-
({ resMatch = constrainResult(tree.symbol, wtp, sharpenedPt); resMatch } || !functionExpected) &&
4063-
((resMatch && !ctx.mode.is(Mode.QuotedPattern)) || !resMatch) =>
4061+
case wtp: MethodType
4062+
if wtp.isImplicitMethod
4063+
&& ({ resMatch = constrainResult(tree.symbol, wtp, sharpenedPt); resMatch} || !functionExpected)
4064+
&& !ctx.mode.is(Mode.InQuotePatternHoasArgs) =>
40644065
if (resMatch || ctx.mode.is(Mode.ImplicitsEnabled))
40654066
adaptNoArgsImplicitMethod(wtp)
40664067
else

0 commit comments

Comments
 (0)