Skip to content

Commit 340ec61

Browse files
committed
Merge pull request #37 from DarkDimius/assertions
Typos, better assertions, dead code
2 parents 356dd4b + 2b4e765 commit 340ec61

23 files changed

+30
-34
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/Constants.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ object Constants {
8585

8686
def booleanValue: Boolean =
8787
if (tag == BooleanTag) value.asInstanceOf[Boolean]
88-
else throw new Error("value " + value + " is not a boolean");
88+
else throw new Error("value " + value + " is not a boolean")
8989

9090
def byteValue: Byte = tag match {
9191
case ByteTag => value.asInstanceOf[Byte]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ object Contexts {
411411

412412
/** Allocate and return next free superclass id */
413413
private[core] def nextSuperId: Int = {
414-
lastSuperId += 1;
414+
lastSuperId += 1
415415
if (lastSuperId >= classOfId.length) {
416416
val tmp = new Array[ClassSymbol](classOfId.length * 2)
417417
classOfId.copyToArray(tmp)

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/Names.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ object Names {
251251
private def equals(index: Int, cs: Array[Char], offset: Int, len: Int): Boolean = {
252252
var i = 0
253253
while ((i < len) && (chrs(index + i) == cs(offset + i)))
254-
i += 1;
254+
i += 1
255255
i == len
256256
}
257257

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ object Scopes {
231231
if (e1 == e)
232232
hashTable(index) = e.tail
233233
else {
234-
while (e1.tail != e) e1 = e1.tail;
234+
while (e1.tail != e) e1 = e1.tail
235235
e1.tail = e.tail
236236
}
237237
}
@@ -243,7 +243,7 @@ object Scopes {
243243
final def unlink(sym: Symbol)(implicit ctx: Context): Unit = {
244244
var e = lookupEntry(sym.name)
245245
while (e ne null) {
246-
if (e.sym == sym) unlink(e);
246+
if (e.sym == sym) unlink(e)
247247
e = lookupNextEntry(e)
248248
}
249249
}

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: 2 additions & 2 deletions
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
}
@@ -120,7 +120,7 @@ class SymbolLoaders {
120120
*/
121121
def binaryOnly(owner: Symbol, name: String)(implicit ctx: Context): Boolean =
122122
name == "package" &&
123-
(owner.fullName == "scala" || owner.fullName == "scala.reflect")
123+
(owner.fullName.toString == "scala" || owner.fullName.toString == "scala.reflect")
124124

125125
/** Initialize toplevel class and module symbols in `owner` from class path representation `classRep`
126126
*/

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/TyperState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TyperState(val reporter: Reporter) extends DotClass with Showable {
3131
}
3232

3333
/** A fresh typer state with the same constraint as this one.
34-
* @param isCommittable The constraint can be committed to an exclosing context.
34+
* @param isCommittable The constraint can be committed to an enclosing context.
3535
*/
3636
def fresh(isCommittable: Boolean): TyperState = this
3737

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/core/pickling/PickleBuffer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
110110
do {
111111
b = readByte()
112112
x = (x << 7) + (b & 0x7f)
113-
} while ((b & 0x80) != 0L);
113+
} while ((b & 0x80) != 0L)
114114
x
115115
}
116116

@@ -158,7 +158,7 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
158158
* @return ...
159159
*/
160160
def until[T](end: Int, op: () => T): List[T] =
161-
if (readIndex == end) List() else op() :: until(end, op);
161+
if (readIndex == end) List() else op() :: until(end, op)
162162

163163
/** Perform operation <code>op</code> the number of
164164
* times specified. Concatenate the results into a list.

src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
2323
ctx.toTextRecursions -= 1
2424
}
2525
else {
26-
recursionLimitExceeeded()
26+
recursionLimitExceeded()
2727
"..."
2828
}
2929

30-
protected def recursionLimitExceeeded() = {
30+
protected def recursionLimitExceeded() = {
3131
ctx.warning("Exceeded recursion depth attempting to print type.")
3232
(new Throwable).printStackTrace
3333
}

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.annotation.switch
1313

1414
class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
1515

16-
override protected def recursionLimitExceeeded() = {}
16+
override protected def recursionLimitExceeded() = {}
1717

1818
protected val PrintableFlags = (ModifierFlags | Label | Module).toCommonFlags
1919

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

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

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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools.dotc.util
22

3-
/** A hash set that allows some priviliged protected access to its internals
3+
/** A hash set that allows some privileged protected access to its internals
44
*/
55
class HashSet[T >: Null <: AnyRef](initialCapacity: Int, loadFactor: Float = 0.25f) extends Set[T] with scala.collection.generic.Clearable {
66
private var used: Int = _

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ object NameTransformer {
9999
def decode(name0: String): String = {
100100
//System.out.println("decode: " + name);//DEBUG
101101
val name = if (name0.endsWith("<init>")) name0.substring(0, name0.length() - ("<init>").length()) + "this"
102-
else name0;
102+
else name0
103103
var buf: StringBuilder = null
104104
val len = name.length()
105105
var i = 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Positions {
1717

1818
/** A position indicates a range between a start offset and an end offset.
1919
* Positions can be synthetic or source-derived. A source-derived position
20-
* has in addition a pointlies somewhere between start and end. The point
20+
* has in addition a point lies somewhere between start and end. The point
2121
* is roughly where the ^ would go if an error was diagnosed at that position.
2222
* All quantities are encoded opaquely in a Long.
2323
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ object ShowPickled {
239239
case SYMANNOT =>
240240
printSymbolRef(); printTypeRef(); buf.until(end, printAnnotArgRef)
241241
case ANNOTATEDtpe =>
242-
printTypeRef(); buf.until(end, printAnnotInfoRef);
242+
printTypeRef(); buf.until(end, printAnnotInfoRef)
243243
case ANNOTINFO =>
244244
printTypeRef(); buf.until(end, printAnnotArgRef)
245245
case ANNOTARGARRAY =>

tests/neg/privates.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
trait T {
2-
private def foo = 0;
2+
private def foo = 0
33
private[this] def bar = 0
44

55
}

0 commit comments

Comments
 (0)