Skip to content

Commit 22205cd

Browse files
committed
Fix to primaryConstructor
Primary constructor was picking last constructor instead of first one. This is now fixed. Also, added paramAccessors utility method.
1 parent b32b45c commit 22205cd

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ object Contexts {
282282
* from constructor parameters to class paramater accessors.
283283
*/
284284
def superCallContext: Context = {
285-
val locals = newScopeWith(owner.decls.filter(_ is ParamAccessor).toList: _*)
285+
val locals = newScopeWith(owner.asClass.paramAccessors: _*)
286286
superOrThisCallContext(owner.primaryConstructor, locals)
287287
}
288288

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ object Denotations {
676676
// ------ PreDenotation ops ----------------------------------------------
677677

678678
final def first = this
679+
final def last = this
679680
final def toDenot(pre: Type)(implicit ctx: Context): Denotation = this
680681
final def containsSym(sym: Symbol): Boolean = hasUniqueSym && (symbol eq sym)
681682
final def containsSig(sig: Signature)(implicit ctx: Context) =
@@ -761,8 +762,9 @@ object Denotations {
761762
/** A denotation in the group exists */
762763
def exists: Boolean
763764

764-
/** First denotation in the group */
765+
/** First/last denotation in the group */
765766
def first: Denotation
767+
def last: Denotation
766768

767769
/** Convert to full denotation by &-ing all elements */
768770
def toDenot(pre: Type)(implicit ctx: Context): Denotation
@@ -827,6 +829,7 @@ object Denotations {
827829
assert(denots1.exists && denots2.exists, s"Union of non-existing denotations ($denots1) and ($denots2)")
828830
def exists = true
829831
def first = denots1.first
832+
def last = denots2.last
830833
def toDenot(pre: Type)(implicit ctx: Context) =
831834
(denots1 toDenot pre) & (denots2 toDenot pre, pre)
832835
def containsSym(sym: Symbol) =

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ object SymDenotations {
431431

432432
/** Does this symbol denote the primary constructor of its enclosing class? */
433433
final def isPrimaryConstructor(implicit ctx: Context) =
434-
isConstructor && owner.primaryConstructor == this
434+
isConstructor && owner.primaryConstructor == symbol
435435

436436
/** Is this a subclass of the given class `base`? */
437437
def isSubClass(base: Symbol)(implicit ctx: Context) = false
@@ -1406,9 +1406,15 @@ object SymDenotations {
14061406

14071407
override def primaryConstructor(implicit ctx: Context): Symbol = {
14081408
val cname = if (this is ImplClass) nme.IMPLCLASS_CONSTRUCTOR else nme.CONSTRUCTOR
1409-
decls.denotsNamed(cname).first.symbol
1409+
decls.denotsNamed(cname).last.symbol // denotsNamed returns Symbols in reverse order of occurrence
14101410
}
14111411

1412+
/** The parameter accessors of this class. Term and type accessors,
1413+
* getters and setters are all returned int his list
1414+
*/
1415+
def paramAccessors(implicit ctx: Context): List[Symbol] =
1416+
decls.filter(_ is ParamAccessor).toList
1417+
14121418
/** If this class has the same `decls` scope reference in `phase` and
14131419
* `phase.next`, install a new denotation with a cloned scope in `phase.next`.
14141420
*/

0 commit comments

Comments
 (0)