Skip to content

Commit 65b0c37

Browse files
committed
Merge pull request #699 from dotty-staging/fix/trait-constructors
Fix trait constructors
2 parents bf6d805 + 1510db9 commit 65b0c37

11 files changed

+19
-52
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ class Compiler {
7676
List(/*new PrivateToStatic,*/
7777
new ExpandPrivate,
7878
new CollectEntryPoints,
79-
new LabelDefs,
80-
new TraitConstructors),
79+
new LabelDefs),
8180
List(new GenBCode)
8281
)
8382

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ object Flags {
388388
/** Symbol is a self name */
389389
final val SelfName = termFlag(54, "<selfname>")
390390

391-
/** Symbol is an implementation class */
391+
/** Symbol is an implementation class of a Scala2 trait */
392392
final val ImplClass = typeFlag(54, "<implclass>")
393393

394394
final val SelfNameOrImplClass = SelfName.toCommonFlags

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ object NameOps {
6262
def likeTyped(n: Name): N =
6363
(if (name.isTermName) n.toTermName else n.toTypeName).asInstanceOf[N]
6464

65-
def isConstructorName = name == CONSTRUCTOR || name == IMPLCLASS_CONSTRUCTOR
65+
def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR
6666
def isExceptionResultName = name startsWith EXCEPTION_RESULT_PREFIX
6767
def isImplClassName = name endsWith IMPL_CLASS_SUFFIX
6868
def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX

src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ object StdNames {
232232
val EVT2U: N = "evt2u$"
233233
val EQEQ_LOCAL_VAR: N = "eqEqTemp$"
234234
val FAKE_LOCAL_THIS: N = "this$"
235-
val IMPLCLASS_CONSTRUCTOR: N = "$init$"
236235
val LAZY_LOCAL: N = "$lzy"
237236
val LAZY_LOCAL_INIT: N = "$lzyINIT"
238237
val LAZY_FIELD_OFFSET: N = "OFFSET$"
@@ -261,6 +260,7 @@ object StdNames {
261260
val SKOLEM: N = "<skolem>"
262261
val SPECIALIZED_INSTANCE: N = "specInstance$"
263262
val THIS: N = "_$this"
263+
val TRAIT_CONSTRUCTOR: N = "$init$"
264264
val U2EVT: N = "u2evt$"
265265

266266
final val Nil: N = "Nil"

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ object SymDenotations {
530530
final def isClassConstructor = name == nme.CONSTRUCTOR
531531

532532
/** Is this the constructor of a trait? */
533-
final def isImplClassConstructor = name == nme.IMPLCLASS_CONSTRUCTOR
533+
final def isImplClassConstructor = name == nme.TRAIT_CONSTRUCTOR
534534

535535
/** Is this the constructor of a trait or a class */
536536
final def isConstructor = name.isConstructorName
@@ -1630,8 +1630,11 @@ object SymDenotations {
16301630
override def fullName(implicit ctx: Context): Name = super.fullName
16311631

16321632
override def primaryConstructor(implicit ctx: Context): Symbol = {
1633-
val cname = if (this is ImplClass) nme.IMPLCLASS_CONSTRUCTOR else nme.CONSTRUCTOR
1634-
info.decls.denotsNamed(cname).last.symbol // denotsNamed returns Symbols in reverse order of occurrence
1633+
def constrNamed(cname: TermName) = info.decls.denotsNamed(cname).last.symbol
1634+
// denotsNamed returns Symbols in reverse order of occurrence
1635+
if (this.is(ImplClass)) constrNamed(nme.TRAIT_CONSTRUCTOR) // ignore normal constructor
1636+
else
1637+
constrNamed(nme.CONSTRUCTOR).orElse(constrNamed(nme.TRAIT_CONSTRUCTOR))
16351638
}
16361639

16371640
/** The parameter accessors of this class. Term and type accessors,

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
438438
}
439439

440440
val name1 = name0.adjustIfModuleClass(flags)
441-
val name = if (name1 == nme.IMPLCLASS_CONSTRUCTOR) nme.CONSTRUCTOR else name1
441+
val name = if (name1 == nme.TRAIT_CONSTRUCTOR) nme.CONSTRUCTOR else name1
442442

443443
def isClassRoot = (name == classRoot.name) && (owner == classRoot.owner) && !(flags is ModuleClass)
444444
def isModuleClassRoot = (name == moduleClassRoot.name) && (owner == moduleClassRoot.owner) && (flags is Module)

src/dotty/tools/dotc/transform/AugmentScala2Traits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform
6060
val mold =
6161
if (meth.isConstructor)
6262
meth.copySymDenotation(
63-
name = nme.IMPLCLASS_CONSTRUCTOR,
63+
name = nme.TRAIT_CONSTRUCTOR,
6464
info = MethodType(Nil, defn.UnitType))
6565
else meth.ensureNotPrivate
6666
meth.copy(

src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import core._
1414
import Phases.Phase
1515
import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTransformers._
1616
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._
17-
import TypeErasure.{ erasure, valueErasure, ErasedValueType }
17+
import TypeErasure.{ valueErasure, ErasedValueType }
1818
import TypeUtils._
1919
import util.Positions._
2020
import Decorators._

src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LinkScala2ImplClasses extends MiniPhaseTransform with IdentityDenotTransfo
5050

5151
private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol =
5252
meth.owner.implClass.info
53-
.decl(if (meth.isConstructor) nme.IMPLCLASS_CONSTRUCTOR else meth.name)
53+
.decl(if (meth.isConstructor) nme.TRAIT_CONSTRUCTOR else meth.name)
5454
.suchThat(c => FullParameterization.memberSignature(c.info) == meth.signature)
5555
.symbol
5656

src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
100100
override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation =
101101
if (sym.is(Accessor, butNot = Deferred) && sym.owner.is(Trait))
102102
sym.copySymDenotation(initFlags = sym.flags &~ ParamAccessor | Deferred).ensureNotPrivate
103-
else if (sym.isConstructor && sym.owner.is(Trait) && sym.info.firstParamTypes.nonEmpty)
104-
sym.copySymDenotation(info = MethodType(Nil, sym.info.resultType))
103+
else if (sym.isConstructor && sym.owner.is(Trait))
104+
sym.copySymDenotation(
105+
name = nme.TRAIT_CONSTRUCTOR,
106+
info = MethodType(Nil, sym.info.resultType))
105107
else
106108
sym
107109

@@ -231,8 +233,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
231233

232234
cpy.Template(impl)(
233235
constr =
234-
if (cls.is(Trait) && impl.constr.vparamss.flatten.nonEmpty)
235-
cpy.DefDef(impl.constr)(vparamss = Nil :: Nil)
236+
if (cls.is(Trait)) cpy.DefDef(impl.constr)(vparamss = Nil :: Nil)
236237
else impl.constr,
237238
parents = impl.parents.map(p => TypeTree(p.tpe).withPos(p.pos)),
238239
body =

src/dotty/tools/dotc/transform/TraitConstructors.scala

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)