Skip to content

Commit

Permalink
Compute correct argument type in ExprMap
Browse files Browse the repository at this point in the history
Fixes #15228
  • Loading branch information
nicolasstucki committed May 23, 2022
1 parent 0181ef9 commit c08026f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/src/scala/quoted/ExprMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ trait ExprMap:
tree
case tree @ Apply(fun, args) =>
val MethodType(_, tpes, _) = fun.tpe.widen: @unchecked
Apply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), transformTerms(args, tpes)(owner))
val tpes1 = tpes.map {
case ByNameType(tpe) => tpe
case tpe => tpe
}
Apply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), transformTerms(args, tpes1)(owner))
case TypeApply(fun, args) =>
TypeApply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), args)
case _: Literal =>
Expand Down
13 changes: 13 additions & 0 deletions tests/pos-macros/i15228/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted.*

inline def mac[T](inline expr: T): T =
${ impl('expr) }

class MyMap() extends ExprMap {
override def transform[T](e: Expr[T])(using Type[T])(using q: Quotes): Expr[T] =
transformChildren(e)
}

def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = {
MyMap().transform(expr)
}
1 change: 1 addition & 0 deletions tests/pos-macros/i15228/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test = mac(None.getOrElse(3))

0 comments on commit c08026f

Please sign in to comment.