|
| 1 | + |
| 2 | +import scala.quoted._ |
| 3 | + |
| 4 | +object TestMethods: |
| 5 | + def a1 = () |
| 6 | + def a2() = () |
| 7 | + def a3[T] = () |
| 8 | + def a4[T]() = () |
| 9 | + |
| 10 | +transparent inline def runMacro() = ${runMacroImpl} |
| 11 | +def runMacroImpl(using Quotes): Expr[Any] = |
| 12 | + import quotes.reflect._ |
| 13 | + |
| 14 | + // ensureApplied test |
| 15 | + Select.unique('{TestMethods}.asTerm, "a1").ensureApplied match |
| 16 | + case Select(_, _) => |
| 17 | + case _ => assert(false) |
| 18 | + Select.unique('{TestMethods}.asTerm, "a2").ensureApplied match |
| 19 | + case Apply(_, _) => |
| 20 | + 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) |
| 34 | + |
| 35 | + // regression test |
| 36 | + val Inlined(_, _, generated) = '{BigDecimal(0).toString()}.asTerm : @unchecked |
| 37 | + val Inlined(_, _, bigDecimal) = '{BigDecimal(0)}.asTerm : @unchecked |
| 38 | + val custom = Select.unique(bigDecimal, "toString").ensureApplied |
| 39 | + // ensure both have the same shape |
| 40 | + assert(custom.toString == generated.toString) |
| 41 | + custom.asExpr |
0 commit comments