-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//> using options -experimental -Yno-experimental | ||
import scala.quoted.* | ||
|
||
inline def testMacro = ${ testImpl } | ||
|
||
transparent inline def transparentTestMacro = ${ testImpl } | ||
|
||
def testImpl(using Quotes): Expr[Object] = { | ||
import quotes.reflect.* | ||
|
||
def makeTypesForClass(owner: Symbol): List[Symbol] = | ||
List( | ||
// type Foo1 >: Int <: String | ||
Symbol.newTypeAlias( | ||
owner, | ||
"Foo", | ||
Flags.EmptyFlags, | ||
TypeBounds(TypeRepr.of[Int], TypeRepr.of[String]), | ||
Symbol.noSymbol | ||
), | ||
// type Foo1 >: [X] =>> Int <: Any | ||
Symbol.newTypeAlias( | ||
owner, | ||
"Foo1", | ||
Flags.EmptyFlags, | ||
TypeBounds(TypeLambda.apply(List("X"), _ => List(TypeBounds.empty), _ => TypeRepr.of[Int]), TypeRepr.of[Any]), | ||
Symbol.noSymbol | ||
), | ||
) | ||
|
||
val clsSymbol = Symbol.newClass(Symbol.spliceOwner, "CLS", List(TypeRepr.of[Object]), sym => makeTypesForClass(sym), None) | ||
val classDef: ClassDef = ClassDef(clsSymbol, List(TypeTree.of[Object]), List(TypeDef(clsSymbol.typeMember("Foo")), TypeDef(clsSymbol.typeMember("Foo1")))) | ||
|
||
Block(List(classDef), Apply(Select(New(TypeIdent(clsSymbol)), clsSymbol.primaryConstructor), List.empty)).asExprOf[Object] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//> using options -experimental -Yno-experimental | ||
def test = | ||
testMacro // error | ||
transparentTestMacro // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters