@@ -196,7 +196,7 @@ class Namer { typer: Typer =>
196
196
val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
197
197
val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
198
198
val SymOfTree : Property .Key [Symbol ] = new Property .Key
199
- val DerivingCompanion : Property .Key [Unit ] = new Property .Key
199
+ val DerivingCompanion : Property .Key [Position ] = new Property .Key
200
200
val Deriver : Property .Key [typer.Deriver ] = new Property .Key
201
201
202
202
/** A partial map from unexpanded member and pattern defs and to their expansions.
@@ -508,7 +508,7 @@ class Namer { typer: Typer =>
508
508
val childStart = child.pos.start
509
509
def insertInto (annots : List [Annotation ]): List [Annotation ] =
510
510
annots.find(_.symbol == defn.ChildAnnot ) match {
511
- case Some (Annotation .Child (other)) if childStart <= other.pos.start =>
511
+ case Some (Annotation .Child (other)) if other.pos.exists && childStart <= other.pos.start =>
512
512
if (child == other)
513
513
annots // can happen if a class has several inaccessible children
514
514
else {
@@ -574,7 +574,7 @@ class Namer { typer: Typer =>
574
574
if (fromTempl.derived.nonEmpty) {
575
575
if (modTempl.derived.nonEmpty)
576
576
ctx.error(em " a class and its companion cannot both have `derives' clauses " , mdef.pos)
577
- res.putAttachment(DerivingCompanion , () )
577
+ res.putAttachment(DerivingCompanion , fromTempl.pos.startPos )
578
578
}
579
579
res
580
580
}
@@ -1012,11 +1012,11 @@ class Namer { typer: Typer =>
1012
1012
typr.println(i " completing $denot, parents = $parents%, %, parentTypes = $parentTypes%, % " )
1013
1013
1014
1014
if (impl.derived.nonEmpty) {
1015
- val derivingClass =
1016
- if (original.removeAttachment( DerivingCompanion ).isDefined ||
1017
- original.mods.is( Synthetic )) cls.companionClass.asClass
1018
- else cls
1019
- val deriver = new Deriver (derivingClass, impl.pos.startPos )(localCtx)
1015
+ val ( derivingClass, derivePos) = original.removeAttachment( DerivingCompanion ) match {
1016
+ case Some (pos) => (cls.companionClass.asClass, pos)
1017
+ case None => ( cls, impl.pos.startPos)
1018
+ }
1019
+ val deriver = new Deriver (derivingClass, derivePos )(localCtx)
1020
1020
deriver.enterDerived(impl.derived)
1021
1021
original.putAttachment(Deriver , deriver)
1022
1022
}
0 commit comments