-
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.
Browse files
Browse the repository at this point in the history
Fix #19842
- Loading branch information
Showing
8 changed files
with
84 additions
and
27 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
26 changes: 8 additions & 18 deletions
26
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,22 @@ | ||
-- 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: assertion failed: Parents of class symbol differs from the parents in the tree for object objectSerializer$macro$1 | ||
| | ||
|Parents in symbol: [class Object, trait Serializer] | ||
|Parents in tree: [class Object, trait Serializer, trait Foo] | ||
| | ||
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8) | ||
| at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:209) | ||
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:257) | ||
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:256) | ||
| at Macros$.makeSerializer(Macro.scala:27) | ||
| | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
|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,31 @@ | ||
//> using options -experimental -Yno-experimental | ||
|
||
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 |