Skip to content

Commit 2a0f9de

Browse files
committed
Fix exception: Any and AnyVal don't have constructors
dotc -d out -Ycheck-init tests/run/vc-equals.scala
1 parent 2f768f3 commit 2a0f9de

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

compiler/src/dotty/tools/dotc/transform/init/Effects.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ object Effects {
4444

4545
/** Field access, `a.f` */
4646
case class FieldAccess(potential: Potential, field: Symbol)(val source: Tree) extends Effect {
47+
assert(field != NoSymbol)
48+
4749
def size: Int = potential.size
4850
def show(implicit ctx: Context): String =
4951
potential.show + "." + field.name.show + "!"
5052
}
5153

5254
/** Method call, `a.m()` */
5355
case class MethodCall(potential: Potential, method: Symbol)(val source: Tree) extends Effect {
56+
assert(method != NoSymbol)
57+
5458
def size: Int = potential.size
5559
def show(implicit ctx: Context): String = potential.show + "." + method.name.show + "!"
5660
}

compiler/src/dotty/tools/dotc/transform/init/Potentials.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,18 @@ object Potentials {
118118

119119
/** The object pointed by `this.f` */
120120
case class FieldReturn(potential: Potential, field: Symbol)(val source: Tree) extends Potential {
121+
assert(field != NoSymbol)
122+
121123
def size: Int = potential.size + 1
122124
def show(implicit ctx: Context): String = potential.show + "." + field.name.show
123125
}
124126

125127
/** The object returned by `this.m()` */
126-
case class MethodReturn(potential: Potential, symbol: Symbol)(val source: Tree) extends Potential {
128+
case class MethodReturn(potential: Potential, method: Symbol)(val source: Tree) extends Potential {
129+
assert(method != NoSymbol)
130+
127131
def size: Int = potential.size + 1
128-
def show(implicit ctx: Context): String = potential.show + "." + symbol.name.show
132+
def show(implicit ctx: Context): String = potential.show + "." + method.name.show
129133
}
130134

131135
/** The object whose initialization status is unknown */

compiler/src/dotty/tools/dotc/transform/init/Summarization.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,13 @@ object Summarization {
288288

289289
case ref =>
290290
val tref: TypeRef = ref.tpe.typeConstructor.asInstanceOf
291-
val ctor = tref.classSymbol.asClass.primaryConstructor
292-
Summarization.analyze(tref.prefix, ref)._2 +
293-
MethodCall(ThisRef(cls)(ref), ctor)(ref)
291+
val cls = tref.classSymbol.asClass
292+
if (cls == defn.AnyClass || cls == defn.AnyValClass) Effects.empty
293+
else {
294+
val ctor = cls.primaryConstructor
295+
Summarization.analyze(tref.prefix, ref)._2 +
296+
MethodCall(ThisRef(cls)(ref), ctor)(ref)
297+
}
294298
})
295299
}
296300

0 commit comments

Comments
 (0)