Skip to content

Commit 99d27ed

Browse files
Merge pull request #6279 from dotty-staging/add-tasty-regression
Add regression for whitebox numeric
2 parents 9ab10e7 + 98afcbd commit 99d27ed

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
5+
trait AddInt[A <: Int, B <: Int] { type Out <: Int }
6+
7+
inline def ff[A <: Int, B <: Int]() <: AddInt[A, B] = ${ impl('[A], '[B]) }
8+
9+
def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(implicit r: tasty.Reflection): Expr[AddInt[A, B]] = {
10+
import r._
11+
12+
val Type.ConstantType(Constant.Int(v1)) = a.unseal.tpe
13+
val Type.ConstantType(Constant.Int(v2)) = b.unseal.tpe
14+
15+
val t = Literal(Constant.Int(v1 + v2)).tpe.seal
16+
17+
'{ null: AddInt[$a, $b] { type Out = $t } }
18+
}
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
val ret = Macro.ff[1, 2]()
3+
val x: ret.Out = 3
4+
val y: 3 = compiletime.constValue[ret.Out]
5+
6+
assert(compiletime.constValue[ret.Out] == 3)
7+
}

0 commit comments

Comments
 (0)