Skip to content

Commit 18cf5d2

Browse files
committed
More informative asserts.
1 parent 92a4fef commit 18cf5d2

10 files changed

+13
-17
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,6 @@ object Trees {
787787

788788
def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
789789
var buf: ListBuffer[Tree[T]] = null
790-
def add(tree: Tree[T]) = {
791-
assert(!tree.isInstanceOf[Thicket[_]])
792-
buf += tree
793-
}
794790
var xs = trees
795791
while (xs.nonEmpty) {
796792
xs.head match {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ object Denotations {
466466
*/
467467
private def bringForward()(implicit ctx: Context): SingleDenotation = this match {
468468
case denot: SymDenotation if ctx.stillValid(denot) =>
469-
if (denot.exists) assert(ctx.runId > validFor.runId)
469+
if (denot.exists) assert(ctx.runId > validFor.runId, s"denotation $denot invalid in run ${ctx.runId}. ValidFor: $validFor")
470470
var d: SingleDenotation = denot
471471
do {
472472
d.validFor = Period(ctx.period.runId, d.validFor.firstPhaseId, d.validFor.lastPhaseId)
@@ -527,7 +527,7 @@ object Denotations {
527527
while (!(cur.validFor contains currentPeriod)) {
528528
cur = cur.nextInRun
529529
cnt += 1
530-
assert(cnt <= MaxPossiblePhaseId)
530+
assert(cnt <= MaxPossiblePhaseId, "seems to be a loop in Denotations")
531531
}
532532
}
533533
cur
@@ -704,7 +704,7 @@ object Denotations {
704704
}
705705

706706
case class DenotUnion(denots1: PreDenotation, denots2: PreDenotation) extends PreDenotation {
707-
assert(denots1.exists && denots2.exists)
707+
assert(denots1.exists && denots2.exists, s"Union of non-existing denotations ($denots1) and ($denots2)")
708708
def exists = true
709709
def first = denots1.first
710710
def toDenot(pre: Type)(implicit ctx: Context) =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ object Flags {
166166

167167
/** The conjunction of all flags in given flag set */
168168
def allOf(flagss: FlagSet*) = {
169-
assert(flagss forall (_.numFlags == 1))
169+
assert(flagss forall (_.numFlags == 1), "Flags.allOf doesn't support flag " + flagss.find(_.numFlags != 1))
170170
FlagConjunction(union(flagss: _*).bits)
171171
}
172172

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ object NameOps {
198198
if (p >= 0)
199199
(name drop (p + TRAIT_SETTER_SEPARATOR.length)).asTermName.setterToGetter
200200
else {
201-
assert(name endsWith SETTER_SUFFIX, name)
201+
assert(name.endsWith(SETTER_SUFFIX), name + " is referenced as a setter but has wrong name format")
202202
name.take(name.length - SETTER_SUFFIX.length).asTermName
203203
}
204204
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ object SymDenotations {
754754

755755
// ----- denotation fields and accessors ------------------------------
756756

757-
if (initFlags is (Module, butNot = Package)) assert(name.isModuleClassName)
757+
if (initFlags is (Module, butNot = Package)) assert(name.isModuleClassName, s"module naming inconsistency: $name")
758758

759759
/** The symbol asserted to have type ClassSymbol */
760760
def classSymbol: ClassSymbol = symbol.asInstanceOf[ClassSymbol]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SymbolLoaders {
2828
protected def enterNew(
2929
owner: Symbol, member: Symbol,
3030
completer: SymbolLoader, scope: Scope = EmptyScope)(implicit ctx: Context): Symbol = {
31-
assert(scope.lookup(member.name) == NoSymbol, owner.fullName + "." + member.name)
31+
assert(scope.lookup(member.name) == NoSymbol, s"${owner.fullName}.${member.name} already has a symbol")
3232
owner.asClass.enter(member, scope)
3333
member
3434
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ object Symbols {
355355
final def isType(implicit ctx: Context): Boolean = denot.isType
356356
final def isClass: Boolean = isInstanceOf[ClassSymbol]
357357

358-
final def asTerm(implicit ctx: Context): TermSymbol = { assert(isTerm); asInstanceOf[TermSymbol] }
359-
final def asType(implicit ctx: Context): TypeSymbol = { assert(isType); asInstanceOf[TypeSymbol] }
358+
final def asTerm(implicit ctx: Context): TermSymbol = { assert(isTerm, s"asTerm called on not-a-Term $this" ); asInstanceOf[TermSymbol] }
359+
final def asType(implicit ctx: Context): TypeSymbol = { assert(isType, s"isType called on not-a-Type $this"); asInstanceOf[TypeSymbol] }
360360
final def asClass: ClassSymbol = asInstanceOf[ClassSymbol]
361361

362362
/** A unique, densely packed integer tag for each class symbol, -1
@@ -367,7 +367,7 @@ object Symbols {
367367

368368
/** This symbol entered into owner's scope (owner must be a class). */
369369
final def entered(implicit ctx: Context): this.type = {
370-
assert(this.owner.isClass) // !!! DEBUG
370+
assert(this.owner.isClass, s"symbol ($this) entered the scope of non-class owner ${this.owner}") // !!! DEBUG
371371
this.owner.asClass.enter(this)
372372
if (this is Module) this.owner.asClass.enter(this.moduleClass)
373373
this

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ object Types {
986986
val prefix: Type
987987
val name: Name
988988

989-
assert(prefix.isValueType || (prefix eq NoPrefix))
989+
assert(prefix.isValueType || (prefix eq NoPrefix), s"invalid prefix $prefix")
990990

991991
private[this] var lastDenotation: Denotation = _
992992
private[this] var lastSymbol: Symbol = _

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ trait Applications extends Compatibility { self: Typer =>
212212
else if (cx.scope != cx.outer.scope &&
213213
cx.denotNamed(methRef.name).hasAltWith(_.symbol == meth)) {
214214
val denot = cx.denotNamed(getterName)
215-
assert(denot.exists)
215+
assert(denot.exists, s"non-existent getter denotation ($denot) for getter($getterName)")
216216
cx.owner.thisType.select(getterName, denot)
217217
} else findDefault(cx.outer)
218218
}

src/dotty/tools/dotc/util/Attachment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object Attachment {
9191
private[Attachment] var next: Link[_] = null
9292

9393
final def pushAttachment[V](key: Key[V], value: V): Unit = {
94-
assert(!getAttachment(key).isDefined)
94+
assert(!getAttachment(key).isDefined, s"duplicate attachment for key $key")
9595
next = new Link(key, value, next)
9696
}
9797
}

0 commit comments

Comments
 (0)