Skip to content

Commit b145f7d

Browse files
committed
Do not wrap into an Apply in ensureApplied if a type parameter is expected
1 parent 6bbd7dc commit b145f7d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
485485
def appliedToNone: Apply =
486486
self.appliedToArgs(Nil)
487487
def ensureApplied: Term =
488-
if (self.tpe.widen.isParameterless) self else self.appliedToNone
488+
def isParameterless(tpe: TypeRepr): Boolean = !tpe.isInstanceOf[MethodType]
489+
if (isParameterless(self.tpe.widen)) self else self.appliedToNone
489490
def appliedToType(targ: TypeRepr): Term =
490491
self.appliedToTypes(targ :: Nil)
491492
def appliedToTypes(targs: List[TypeRepr]): Term =

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
890890
/** The current tree applied to (): `tree()` */
891891
def appliedToNone: Apply
892892

893-
/** The current tree applied to `()` unless the tree's widened type is parameterless */
893+
/** The current tree applied to `()` unless the tree's widened type is parameterless or expects type parameters */
894894
def ensureApplied: Term
895895

896896
/** The current tree applied to given type argument: `tree[targ]` */

tests/pos-macros/i23969/Macro.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import scala.quoted._
44
object TestMethods:
55
def a1 = ()
66
def a2() = ()
7+
def a3[T] = ()
8+
def a4[T]() = ()
79

810
transparent inline def runMacro() = ${runMacroImpl}
911
def runMacroImpl(using Quotes): Expr[Any] =
@@ -16,6 +18,19 @@ def runMacroImpl(using Quotes): Expr[Any] =
1618
Select.unique('{TestMethods}.asTerm, "a2").ensureApplied match
1719
case Apply(_, _) =>
1820
case _ => assert(false)
21+
Select.unique('{TestMethods}.asTerm, "a3").ensureApplied match
22+
case Select(_, _) =>
23+
case other => assert(false)
24+
Select.unique('{TestMethods}.asTerm, "a4").ensureApplied match
25+
case Select(_, _) =>
26+
case other => assert(false)
27+
28+
TypeApply(Select.unique('{TestMethods}.asTerm, "a3"), List(TypeTree.of[Nothing])).ensureApplied match
29+
case TypeApply(_, _) =>
30+
case other => assert(false)
31+
TypeApply(Select.unique('{TestMethods}.asTerm, "a4"), List(TypeTree.of[Nothing])).ensureApplied match
32+
case Apply(_, _) =>
33+
case other => assert(false)
1934

2035
// regression test
2136
val Inlined(_, _, generated) = '{BigDecimal(0).toString()}.asTerm : @unchecked

0 commit comments

Comments
 (0)