-
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.
Add check for parents in Quotes (#i19842)
- Loading branch information
1 parent
469c980
commit deaec4b
Showing
7 changed files
with
62 additions
and
22 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
24 changes: 3 additions & 21 deletions
24
tests/neg-macros/i19842.check → tests/neg-macros/i19842-a.check
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
File renamed without changes.
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,14 @@ | ||
-- Error: tests/neg-macros/i19842-b/Test.scala:9:50 -------------------------------------------------------------------- | ||
9 |@main def Test = summon[Serializer[ValidationCls]] // error | ||
| ^ | ||
| Exception occurred while executing macro expansion. | ||
| java.lang.AssertionError: Parents in the symbol are not compatible with the provided parents | ||
| at Macros$.makeSerializer(Macro.scala:26) | ||
| | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
|Inline stack trace | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|This location contains code that was inlined from Test.scala:5 | ||
5 | implicit inline def implicitMakeSerializer[T]: Serializer[T] = ${ Macros.makeSerializer[T] } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
--------------------------------------------------------------------------------------------------------------------- |
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,30 @@ | ||
|
||
import scala.annotation.{experimental, targetName} | ||
import scala.quoted.* | ||
import scala.util.Try | ||
|
||
trait Foo | ||
|
||
object Macros { | ||
def makeSerializer[T: Type](using Quotes): Expr[Serializer[T]] = { | ||
import quotes.reflect.* | ||
|
||
val tpe: TypeRepr = TypeRepr.of[T] | ||
val name: String = Symbol.freshName("objectSerializer") | ||
|
||
val modSym: Symbol = Symbol.newModule( | ||
Symbol.spliceOwner, | ||
name, | ||
Flags.Implicit, | ||
Flags.EmptyFlags, | ||
List(TypeRepr.of[Object], TypeRepr.of[Serializer[T]]), | ||
_ => Nil, | ||
Symbol.noSymbol | ||
) | ||
|
||
val (modValDef: ValDef, modClassDef: ClassDef) = | ||
ClassDef.module(modSym, List(TypeTree.of[Object], TypeTree.of[Serializer[T]], TypeTree.of[Foo]), Nil) | ||
|
||
Block(List(modValDef, modClassDef), Ref(modSym)).asExprOf[Serializer[T]] | ||
} | ||
} |
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,9 @@ | ||
|
||
trait Serializer[@specialized T] | ||
|
||
object Serializer: | ||
implicit inline def implicitMakeSerializer[T]: Serializer[T] = ${ Macros.makeSerializer[T] } | ||
|
||
case class ValidationCls(string: String) | ||
|
||
@main def Test = summon[Serializer[ValidationCls]] // error |