Skip to content

Commit

Permalink
Fix #12128: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed May 25, 2021
1 parent e2e77b5 commit c54faa0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/init/crash/i12128/Macro_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import scala.quoted._
import scala.language.experimental.macros

object MacroCompat {
trait LocationMacro {
inline implicit def generate: Location = ${ locationImpl() }
implicit def generate: Location = macro MacroCompatScala2.locationImpl
}

def locationImpl()(using Quotes): Expr[Location] = '{ new Location(${Expr(0)}) }
}

object MacroCompatScala2 {
def locationImpl(c: Context): c.Tree = {
import c.universe._
val line = Literal(Constant(c.enclosingPosition.line))
New(c.mirror.staticClass(classOf[Location].getName()), line)
}
}
30 changes: 30 additions & 0 deletions tests/init/crash/i12128/Reflect_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
trait Context: // Dummy scala.reflect.macros.Context
type Tree = universe.Tree
val universe: Universe

trait Universe {
type Tree >: Null <: AnyRef with TreeApi
type Literal >: Null <: LiteralApi with TermTree
type TermTree >: Null <: TermTreeApi with Tree

trait TermTreeApi extends TreeApi { this: TermTree => }
trait LiteralApi extends TermTreeApi { this: Literal => }
trait TreeApi extends Product { this: Tree => }

type Constant

type Type

def Literal(const: Constant): Tree
def Constant(i: Int): Constant
def New(tpe: Type, arg: Tree): Tree
}

def enclosingPosition: Location

trait Mirror {
def staticClass(name: String): universe.Type
}
val mirror: Mirror

class Location(val line: Int)
1 change: 1 addition & 0 deletions tests/init/crash/i12128/Test_3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object Test extends MacroCompat.LocationMacro

0 comments on commit c54faa0

Please sign in to comment.