Skip to content

Commit 20e88f3

Browse files
Merge pull request #15269 from dotty-staging/fix-15228
Compute correct argument type in ExprMap
2 parents 67e692d + c08026f commit 20e88f3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

library/src/scala/quoted/ExprMap.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ trait ExprMap:
4949
tree
5050
case tree @ Apply(fun, args) =>
5151
val MethodType(_, tpes, _) = fun.tpe.widen: @unchecked
52-
Apply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), transformTerms(args, tpes)(owner))
52+
val tpes1 = tpes.map {
53+
case ByNameType(tpe) => tpe
54+
case tpe => tpe
55+
}
56+
Apply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), transformTerms(args, tpes1)(owner))
5357
case TypeApply(fun, args) =>
5458
TypeApply.copy(tree)(transformTerm(fun, TypeRepr.of[Any])(owner), args)
5559
case _: Literal =>

tests/pos-macros/i15228/Macro_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.quoted.*
2+
3+
inline def mac[T](inline expr: T): T =
4+
${ impl('expr) }
5+
6+
class MyMap() extends ExprMap {
7+
override def transform[T](e: Expr[T])(using Type[T])(using q: Quotes): Expr[T] =
8+
transformChildren(e)
9+
}
10+
11+
def impl[T: Type](expr: Expr[T])(using quotes: Quotes): Expr[T] = {
12+
MyMap().transform(expr)
13+
}

tests/pos-macros/i15228/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test = mac(None.getOrElse(3))

0 commit comments

Comments
 (0)