-
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.
Split Symbol.newType into 2 methods and add tests
- Loading branch information
Showing
10 changed files
with
93 additions
and
19 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
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,22 @@ | ||
//> 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 makeType(owner: Symbol): Symbol = | ||
Symbol.newBoundedType(owner, "mytype", Flags.EmptyFlags, TypeBounds.lower(TypeRepr.of[String]), Symbol.noSymbol) | ||
|
||
val typeDef = TypeDef(makeType(Symbol.spliceOwner)) | ||
// Expr printer does not work here, see comment: | ||
// https://github.com/scala/scala3/pull/20347#issuecomment-2096824617 | ||
assert(typeDef.toString == "TypeDef(mytype,TypeTree[TypeBounds(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class java)),object lang),String),TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any))])") | ||
|
||
val clsSymbol = Symbol.newClass(Symbol.spliceOwner, "CLS", List(TypeRepr.of[Object]), sym => List(makeType(sym)), None) | ||
val classDef: ClassDef = ClassDef(clsSymbol, List(TypeTree.of[Object]), List(TypeDef(clsSymbol.typeMember("mytype")))) | ||
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 | ||
transparentTestMacro |
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,18 @@ | ||
//> 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 makeType(owner: Symbol): Symbol = | ||
Symbol.newTypeAlias(owner, "mytype", Flags.EmptyFlags, TypeRepr.of[String], Symbol.noSymbol) | ||
|
||
val clsSymbol = Symbol.newClass(Symbol.spliceOwner, "CLS", List(TypeRepr.of[Object]), sym => List(makeType(sym)), None) | ||
val classDef: ClassDef = ClassDef(clsSymbol, List(TypeTree.of[Object]), List(TypeDef(clsSymbol.typeMember("mytype")))) | ||
|
||
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 | ||
transparentTestMacro |
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,13 @@ | ||
//> using options -experimental -Yno-experimental | ||
import scala.quoted.* | ||
|
||
inline def testMacro = ${ testImpl } | ||
|
||
def testImpl(using Quotes): Expr[Unit] = { | ||
import quotes.reflect.* | ||
val sym = Symbol.newTypeAlias(Symbol.spliceOwner, "mytype", Flags.EmptyFlags, TypeRepr.of[String], Symbol.noSymbol) | ||
val typeDef = TypeDef(sym) | ||
assert(typeDef.show == "type mytype = java.lang.String") | ||
|
||
Block(List(typeDef), '{()}.asTerm).asExprOf[Unit] | ||
} |
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,2 @@ | ||
//> using options -experimental -Yno-experimental | ||
def test = testMacro |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.