Skip to content

Commit c54faa0

Browse files
committed
Fix #12128: Add test
1 parent e2e77b5 commit c54faa0

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

tests/init/crash/i12128/Macro_2.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.quoted._
2+
import scala.language.experimental.macros
3+
4+
object MacroCompat {
5+
trait LocationMacro {
6+
inline implicit def generate: Location = ${ locationImpl() }
7+
implicit def generate: Location = macro MacroCompatScala2.locationImpl
8+
}
9+
10+
def locationImpl()(using Quotes): Expr[Location] = '{ new Location(${Expr(0)}) }
11+
}
12+
13+
object MacroCompatScala2 {
14+
def locationImpl(c: Context): c.Tree = {
15+
import c.universe._
16+
val line = Literal(Constant(c.enclosingPosition.line))
17+
New(c.mirror.staticClass(classOf[Location].getName()), line)
18+
}
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
trait Context: // Dummy scala.reflect.macros.Context
2+
type Tree = universe.Tree
3+
val universe: Universe
4+
5+
trait Universe {
6+
type Tree >: Null <: AnyRef with TreeApi
7+
type Literal >: Null <: LiteralApi with TermTree
8+
type TermTree >: Null <: TermTreeApi with Tree
9+
10+
trait TermTreeApi extends TreeApi { this: TermTree => }
11+
trait LiteralApi extends TermTreeApi { this: Literal => }
12+
trait TreeApi extends Product { this: Tree => }
13+
14+
type Constant
15+
16+
type Type
17+
18+
def Literal(const: Constant): Tree
19+
def Constant(i: Int): Constant
20+
def New(tpe: Type, arg: Tree): Tree
21+
}
22+
23+
def enclosingPosition: Location
24+
25+
trait Mirror {
26+
def staticClass(name: String): universe.Type
27+
}
28+
val mirror: Mirror
29+
30+
class Location(val line: Int)

tests/init/crash/i12128/Test_3.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
object Test extends MacroCompat.LocationMacro

0 commit comments

Comments
 (0)