Skip to content

Commit 22bb628

Browse files
author
gorilskij
committed
add tests
1 parent 35eb305 commit 22bb628

File tree

8 files changed

+249
-0
lines changed

8 files changed

+249
-0
lines changed

tests/pos/i8577/MacroA_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroA:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyA(sc: Expr[MacroB.StringContext], input: Expr[Int])
11+
(using Quotes): Expr[Option[Seq[Int]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroB_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroB:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyB[U](sc: Expr[MacroB.StringContext], input: Expr[U])
11+
(using Type[U])(using Quotes): Expr[Option[Seq[U]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroC_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroC:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyC[T](sc: Expr[MacroC.StringContext], input: Expr[T])
11+
(using Type[T])(using Quotes): Expr[Option[Seq[T]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroD_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroD:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyD[T](sc: Expr[MacroD.StringContext], input: Expr[T])
11+
(using Type[T])(using Quotes): Expr[Option[Seq[T]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroE_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroE:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyE[T, U](sc: Expr[MacroE.StringContext], input: Expr[U])
11+
(using Type[U])(using Quotes): Expr[Option[Seq[U]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroF_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroF:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyF[T, U](sc: Expr[MacroF.StringContext], input: Expr[(T, U)])
11+
(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[(T, U)]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/MacroG_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package i8577
2+
3+
import scala.quoted._
4+
5+
object MacroG:
6+
opaque type StringContext = scala.StringContext
7+
def apply(ctx: scala.StringContext): StringContext = ctx
8+
def unapply(ctx: StringContext): Option[scala.StringContext] = Some(ctx)
9+
10+
def implUnapplyG[T, U](sc: Expr[MacroG.StringContext], input: Expr[T | U])
11+
(using Type[T], Type[U])(using Quotes): Expr[Option[Seq[T | U]]] =
12+
'{ Some(Seq(${input})) }

tests/pos/i8577/Main_2.scala

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package i8577
2+
3+
def main: Unit = {
4+
{
5+
extension (ctx: StringContext) def macroA: MacroB.StringContext = MacroB(ctx)
6+
extension (inline ctx: MacroB.StringContext) inline def unapplySeq(inline input: Int): Option[Seq[Int]] =
7+
${implUnapplyA('ctx, 'input)}
8+
9+
val macroA"$xA" = 1
10+
}
11+
12+
{
13+
extension (ctx: StringContext) def macroB: MacroB.StringContext = MacroB(ctx)
14+
extension (inline ctx: MacroB.StringContext) inline def unapplySeq[U](inline input: U): Option[Seq[U]] =
15+
${ implUnapplyB('ctx, 'input) }
16+
17+
val macroB"$xB" = 2
18+
}
19+
20+
{
21+
extension (ctx: StringContext) def macroC: MacroC.StringContext = MacroC(ctx)
22+
extension [T] (inline ctx: MacroC.StringContext) inline def unapplySeq(inline input: T): Option[Seq[T]] =
23+
${ implUnapplyC('ctx, 'input) }
24+
25+
// compiler error
26+
// val macroC"$xC" = 3
27+
}
28+
29+
{
30+
extension (ctx: StringContext) def macroD: MacroD.StringContext = MacroD(ctx)
31+
extension [T] (inline ctx: MacroD.StringContext) inline def unapplySeq[U](inline input: T): Option[Seq[T]] =
32+
${ implUnapplyD('ctx, 'input) }
33+
34+
// miscompilation
35+
// val macroD"$xD" = 4
36+
}
37+
38+
{
39+
extension (ctx: StringContext) def macroE: MacroE.StringContext = MacroE(ctx)
40+
extension [T] (inline ctx: MacroE.StringContext) inline def unapplySeq[U](inline input: U): Option[Seq[U]] =
41+
${ implUnapplyE('ctx, 'input) }
42+
43+
val macroE"$xE" = 5
44+
}
45+
46+
{
47+
extension (ctx: StringContext) def macroF: MacroF.StringContext = MacroF(ctx)
48+
extension [T] (inline ctx: MacroF.StringContext) inline def unapplySeq[U](inline input: (T, U)): Option[Seq[(T, U)]] =
49+
${ implUnapplyF('ctx, 'input) }
50+
51+
val macroF"$xF" = (6, 7)
52+
53+
// miscompilation
54+
// val macroF"$xF" = (6, "7")
55+
}
56+
57+
{
58+
extension (ctx: StringContext) def macroG: MacroG.StringContext = MacroG(ctx)
59+
extension [T] (inline ctx: MacroG.StringContext) inline def unapplySeq[U](inline input: T | U): Option[Seq[T | U]] =
60+
${ implUnapplyG('ctx, 'input) }
61+
62+
// compiler error
63+
// val macroG"$xG" = 8
64+
}
65+
}
66+
67+
// {
68+
// // B
69+
// object F2
70+
// extension (o: F2.type) inline def unapplySeq[T](inline x: T) = Some(Seq(x))
71+
//
72+
// val F2(x) = 16
73+
// println(s"F2: $x")
74+
// }
75+
//
76+
// {
77+
// // C
78+
// object F1
79+
// extension [T] (o: F1.type) inline def unapplySeq(inline x: T) = Some(Seq(x))
80+
//
81+
// val F1(x) = 15
82+
// println(s"F1: $x")
83+
// }
84+
//
85+
// {
86+
// // D
87+
// object F4b
88+
// extension [T] (o: F4b.type) inline def unapplySeq[U](inline x: T) = Some(Seq(x))
89+
//
90+
// val F4b(x) = 18.2
91+
// println(s"F4b: $x")
92+
// }
93+
//
94+
// {
95+
// // E
96+
// object F4b
97+
// extension [T] (o: F4b.type) inline def unapplySeq[U](inline x: U) = Some(Seq(x))
98+
//
99+
// val F4b(x) = 18.2
100+
// println(s"F4b: $x")
101+
// }
102+
//
103+
// {
104+
// // F
105+
// object F4d
106+
// extension [T] (o: F4d.type) inline def unapplySeq[U](inline x: (T, U)) = Some(Seq(x))
107+
//
108+
// val F4d(x) = (18.4, 18.5)
109+
// println(s"F4d: $x")
110+
// }
111+
//
112+
// {
113+
// // G
114+
// object H1
115+
// extension (inline o: H1.type) inline def unapplySeq(inline x: Int) = Some(Seq(x))
116+
//
117+
// val H1(x) = 23
118+
// println(s"H1: $x")
119+
// }
120+
//
121+
// {
122+
// // H
123+
// object H2
124+
// extension (inline o: H2.type) inline def unapplySeq[T](inline x: T) = Some(Seq(x))
125+
//
126+
// val H2(x) = 24
127+
// println(s"H2: $x")
128+
// }
129+
//
130+
// {
131+
// // I
132+
// object H2
133+
// extension [T] (inline o: H2.type) inline def unapplySeq(inline x: T) = Some(Seq(x))
134+
//
135+
// val H2(x) = 24
136+
// println(s"H2: $x")
137+
// }
138+
//
139+
// {
140+
// // J
141+
// object H2
142+
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: T) = Some(Seq(x))
143+
//
144+
// val H2(x) = 24
145+
// println(s"H2: $x")
146+
// }
147+
//
148+
// {
149+
// // K
150+
// object H2
151+
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: U) = Some(Seq(x))
152+
//
153+
// val H2(x) = 24
154+
// println(s"H2: $x")
155+
// }
156+
//
157+
// {
158+
// // L
159+
// object H2
160+
// extension [T] (inline o: H2.type) inline def unapplySeq[U](inline x: (T, U)) = Some(Seq(x))
161+
//
162+
// val H2(x) = (24, "a")
163+
// println(s"H2: $x")
164+
// }
165+
//}

0 commit comments

Comments
 (0)