Skip to content

Commit

Permalink
Add check for parents in Quotes (#i19842)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed Mar 4, 2024
1 parent 469c980 commit 9f6b693
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
1 change: 1 addition & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
(cdef.name.toString, cdef.constructor, cdef.parents, cdef.self, rhs.body)

def module(module: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): (ValDef, ClassDef) = {
xCheckMacroAssert(parents.nonEmpty && !parents.head.tpe.dealias.classSymbol.is(dotc.core.Flags.Trait), "First parent must be a class")
val cls = module.moduleClass
val clsDef = ClassDef(cls, parents, body)
val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil)
Expand Down
24 changes: 3 additions & 21 deletions tests/neg-macros/i19842.check
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
-- Error: tests/neg-macros/i19842/Test.scala:9:50 ----------------------------------------------------------------------
9 |@main def Test = summon[Serializer[ValidationCls]] // error
| ^
|Malformed tree was found while expanding macro with -Xcheck-macros.
|The tree does not conform to the compiler's tree invariants.
| Exception occurred while executing macro expansion.
| java.lang.AssertionError: First parent must be a class
| at Macros$.makeSerializer(Macro.scala:24)
|
|Macro was:
|scala.quoted.runtime.Expr.splice[Serializer[ValidationCls]](((contextual$2: scala.quoted.Quotes) ?=> Macros.makeSerializer[ValidationCls](scala.quoted.Type.of[ValidationCls](contextual$2), contextual$2)))
|
|The macro returned:
|{
| object objectSerializer$macro$1 extends Serializer[ValidationCls] { this: objectSerializer$macro$1.type =>
|
| }
| objectSerializer$macro$1
|}
|
|Error:
|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: [trait Serializer]
|
|
|stacktrace available when compiling with `-Ydebug`
|---------------------------------------------------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i19842/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ object Macros {
name,
Flags.Implicit,
Flags.EmptyFlags,
// Without TypeRep.of[Object] it would fail with java.lang.AssertionError: assertion failed: First parent must be a class
List(TypeRepr.of[Object], TypeRepr.of[Serializer[T]]),
_ => Nil,
Symbol.noSymbol
Expand Down

0 comments on commit 9f6b693

Please sign in to comment.