Skip to content

Commit cc4eeb5

Browse files
Merge pull request #9146 from dotty-staging/fix-constructor
Fix incorrect code in phase Constructors
2 parents bf3d60a + 3c61bca commit cc4eeb5

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

compiler/src/dotty/tools/dotc/core/NameOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object NameOps {
270270
original.fieldName
271271
}
272272
else getterName.fieldName
273-
else FieldName(name)
273+
else FieldName(name.toSimpleName)
274274

275275
def stripScala2LocalSuffix: TermName =
276276
if (name.isScala2LocalSuffix) name.asSimpleName.dropRight(1) else name

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class TreeUnpickler(reader: TastyReader,
578578
else
579579
ctx.newSymbol(ctx.owner, name, flags, completer, privateWithin, coord)
580580
}
581-
sym.annotations = annotFns.map(_(sym))
581+
sym.annotations = annotFns.map(_(sym.owner))
582582
if sym.isOpaqueAlias then sym.setFlag(Deferred)
583583
val isScala2MacroDefinedInScala3 = flags.is(Macro, butNot = Inline) && flags.is(Erased)
584584
ctx.owner match {

compiler/src/dotty/tools/dotc/transform/Constructors.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
251251
// Drop accessors that are not retained from class scope
252252
if (dropped.nonEmpty) {
253253
val clsInfo = cls.classInfo
254-
cls.copy(
255-
info = clsInfo.derivedClassInfo(
256-
decls = clsInfo.decls.filteredScope(!dropped.contains(_))))
254+
val decls = clsInfo.decls.filteredScope(!dropped.contains(_))
255+
val clsInfo2 = clsInfo.derivedClassInfo(decls = decls)
256+
cls.copySymDenotation(info = clsInfo2).installAfter(thisPhase)
257257
// TODO: this happens to work only because Constructors is the last phase in group
258258
}
259259

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
2222
val res = member.copy(
2323
owner = cls,
2424
name = member.name.stripScala2LocalSuffix,
25-
flags = member.flags &~ Deferred | Synthetic | extraFlags,
25+
flags = member.flags &~ Deferred &~ Module | Synthetic | extraFlags,
2626
info = cls.thisType.memberInfo(member)).enteredAfter(thisPhase).asTerm
2727
res.addAnnotations(member.annotations.filter(_.symbol != defn.TailrecAnnot))
2828
res

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class ReifyQuotes extends MacroTransform {
270270

271271
val tpe = MethodType(defn.SeqType.appliedTo(defn.AnyType) :: Nil, tree.tpe.widen)
272272
val meth = ctx.newSymbol(lambdaOwner, UniqueName.fresh(nme.ANON_FUN), Synthetic | Method, tpe)
273-
Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth)).withSpan(tree.span)
273+
Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeNonLocalOwners(meth)).withSpan(tree.span)
274274
}
275275

276276
private def transformWithCapturer(tree: Tree)(capturer: mutable.Map[Symbol, Tree] => Tree => Tree)(implicit ctx: Context): Tree = {

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

+10-9
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,19 @@ class TreeChecker extends Phase with SymTransformer {
427427
checkOwner(impl)
428428
checkOwner(impl.constr)
429429

430-
def isNonMagicalMethod(x: Symbol) =
431-
x.is(Method) &&
432-
!x.isValueClassConvertMethod &&
433-
!(x.is(Macro) && ctx.phase.refChecked) &&
434-
!x.name.is(DocArtifactName)
430+
def isNonMagicalMember(x: Symbol) =
431+
!x.isValueClassConvertMethod &&
432+
!x.name.is(DocArtifactName)
435433

436-
val symbolsNotDefined = cls.classInfo.decls.toList.toSet.filter(isNonMagicalMethod) -- impl.body.map(_.symbol) - constr.symbol
434+
val decls = cls.classInfo.decls.toList.toSet.filter(isNonMagicalMember)
435+
val defined = impl.body.map(_.symbol)
436+
437+
val symbolsNotDefined = decls -- defined - constr.symbol
437438

438439
assert(symbolsNotDefined.isEmpty,
439-
i" $cls tree does not define methods: ${symbolsNotDefined.toList}%, %\n" +
440-
i"expected: ${cls.classInfo.decls.toList.toSet.filter(isNonMagicalMethod)}%, %\n" +
441-
i"defined: ${impl.body.map(_.symbol)}%, %")
440+
i" $cls tree does not define members: ${symbolsNotDefined.toList}%, %\n" +
441+
i"expected: ${decls.toList}%, %\n" +
442+
i"defined: ${defined}%, %")
442443

443444
super.typedClassDef(cdef, cls)
444445
}

compiler/src/dotty/tools/dotc/typer/Namer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ class Namer { typer: Typer =>
858858
if (cls eq sym)
859859
ctx.error("An annotation class cannot be annotated with iself", annotTree.sourcePos)
860860
else {
861-
val ann = Annotation.deferred(cls)(typedAnnotation(annotTree))
861+
val ann = Annotation.deferred(cls)(typedAheadAnnotation(annotTree)(using annotCtx))
862862
sym.addAnnotation(ann)
863863
}
864864
}

0 commit comments

Comments
 (0)