Skip to content

Commit 9f6b693

Browse files
committed
Add check for parents in Quotes (#i19842)
1 parent 469c980 commit 9f6b693

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
253253
(cdef.name.toString, cdef.constructor, cdef.parents, cdef.self, rhs.body)
254254

255255
def module(module: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): (ValDef, ClassDef) = {
256+
xCheckMacroAssert(parents.nonEmpty && !parents.head.tpe.dealias.classSymbol.is(dotc.core.Flags.Trait), "First parent must be a class")
256257
val cls = module.moduleClass
257258
val clsDef = ClassDef(cls, parents, body)
258259
val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil)

tests/neg-macros/i19842.check

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,10 @@
11
-- Error: tests/neg-macros/i19842/Test.scala:9:50 ----------------------------------------------------------------------
22
9 |@main def Test = summon[Serializer[ValidationCls]] // error
33
| ^
4-
|Malformed tree was found while expanding macro with -Xcheck-macros.
5-
|The tree does not conform to the compiler's tree invariants.
4+
| Exception occurred while executing macro expansion.
5+
| java.lang.AssertionError: First parent must be a class
6+
| at Macros$.makeSerializer(Macro.scala:24)
67
|
7-
|Macro was:
8-
|scala.quoted.runtime.Expr.splice[Serializer[ValidationCls]](((contextual$2: scala.quoted.Quotes) ?=> Macros.makeSerializer[ValidationCls](scala.quoted.Type.of[ValidationCls](contextual$2), contextual$2)))
9-
|
10-
|The macro returned:
11-
|{
12-
| object objectSerializer$macro$1 extends Serializer[ValidationCls] { this: objectSerializer$macro$1.type =>
13-
|
14-
| }
15-
| objectSerializer$macro$1
16-
|}
17-
|
18-
|Error:
19-
|assertion failed: Parents of class symbol differs from the parents in the tree for object objectSerializer$macro$1
20-
|
21-
|Parents in symbol: [class Object, trait Serializer]
22-
|Parents in tree: [trait Serializer]
23-
|
24-
|
25-
|stacktrace available when compiling with `-Ydebug`
268
|---------------------------------------------------------------------------------------------------------------------
279
|Inline stack trace
2810
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

tests/neg-macros/i19842/Macro.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ object Macros {
1515
name,
1616
Flags.Implicit,
1717
Flags.EmptyFlags,
18-
// Without TypeRep.of[Object] it would fail with java.lang.AssertionError: assertion failed: First parent must be a class
1918
List(TypeRepr.of[Object], TypeRepr.of[Serializer[T]]),
2019
_ => Nil,
2120
Symbol.noSymbol

0 commit comments

Comments
 (0)