Skip to content
This repository

Lint-like fixes found by Semmle #2693

Merged
merged 5 commits into from 10 months ago

4 participants

lexspoon Adriaan Moors scala-jenkins
lexspoon

No description provided.

lexspoon

I played around with Semmle's whole-program code scanner on the Scala
repository, and I found a few lint-like issues that seem worth
cleaning up. These queries are fun in that they aren't limited to the files
available in any single compilation run. For example, they can find unsealed
case class hierarchies that aren't extended in another file.

Adriaan Moors
Owner

LGTM, thanks!

soc commented June 29, 2013

LGTM!

Adriaan Moors
Owner

Conclusion: IDE still compiles, so good to merge.

Adriaan Moors adriaanm merged commit c1451cf into from July 01, 2013
Adriaan Moors adriaanm closed this July 01, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+build
15  lib/.gitignore
... ...
@@ -0,0 +1,15 @@
  1
+ant-contrib.jar
  2
+ant-dotnet-1.0.jar
  3
+ant.jar
  4
+fjbg.jar
  5
+forkjoin.jar
  6
+jline.jar
  7
+maven-ant-tasks-2.1.1.jar
  8
+msil.jar
  9
+scala-compiler.jar
  10
+scala-compiler-src.jar
  11
+scala-library.jar
  12
+scala-library-src.jar
  13
+scala-reflect.jar
  14
+scala-reflect-src.jar
  15
+vizant.jar
14  src/compiler/scala/tools/ant/sabbus/Settings.scala
@@ -93,4 +93,18 @@ class Settings {
93 93
     case _ => false
94 94
   }
95 95
 
  96
+  override lazy val hashCode: Int = Seq(
  97
+    gBf,
  98
+    uncheckedBf,
  99
+    classpathBf,
  100
+    sourcepathBf,
  101
+    sourcedirBf,
  102
+    bootclasspathBf,
  103
+    extdirsBf,
  104
+    dBf,
  105
+    encodingBf,
  106
+    targetBf,
  107
+    optimiseBf,
  108
+    extraParamsBf
  109
+  ).##
96 110
 }
2  src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1747,7 +1747,7 @@ abstract class GenICode extends SubComponent  {
1747 1747
 
1748 1748
     /////////////////////// Context ////////////////////////////////
1749 1749
 
1750  
-    abstract class Cleanup(val value: AnyRef) {
  1750
+    sealed abstract class Cleanup(val value: AnyRef) {
1751 1751
       def contains(x: AnyRef) = value == x
1752 1752
     }
1753 1753
     case class MonitorRelease(m: Local) extends Cleanup(m) { }
8  src/compiler/scala/tools/nsc/backend/icode/Members.scala
@@ -108,6 +108,14 @@ trait Members {
108 108
       if (symbol eq other.symbol) 0
109 109
       else if (symbol isLess other.symbol) -1
110 110
       else 1
  111
+
  112
+    override def equals(other: Any): Boolean =
  113
+      other match {
  114
+        case other: IMember => (this compare other) == 0
  115
+        case _ => false
  116
+      }
  117
+
  118
+    override def hashCode = symbol.##
111 119
   }
112 120
 
113 121
   /** Represent a class in ICode */
2  src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala
@@ -27,7 +27,7 @@ abstract class CopyPropagation {
27 27
   case object This extends Location
28 28
 
29 29
   /** Values that can be on the stack. */
30  
-  abstract class Value { }
  30
+  sealed abstract class Value { }
31 31
   case class Record(cls: Symbol, bindings: mutable.Map[Symbol, Value]) extends Value { }
32 32
   /** The value of some location in memory. */
33 33
   case class Deref(l: Location) extends Value
4  src/compiler/scala/tools/nsc/dependencies/Changes.scala
@@ -16,7 +16,7 @@ abstract class Changes {
16 16
   import compiler._
17 17
   import symtab.Flags._
18 18
 
19  
-  abstract class Change
  19
+  sealed abstract class Change
20 20
 
21 21
   private lazy val annotationsChecked =
22 22
     List(definitions.SpecializedClass) // Any others that should be checked?
@@ -38,7 +38,7 @@ abstract class Changes {
38 38
   /** An entity in source code, either a class or a member definition.
39 39
    *  Name is fully-qualified.
40 40
    */
41  
-  abstract class Entity
  41
+  sealed abstract class Entity
42 42
   case class Class(name: String) extends Entity
43 43
   case class Definition(name: String) extends Entity
44 44
 
2  src/compiler/scala/tools/nsc/settings/ScalaVersion.scala
@@ -11,7 +11,7 @@ package tools.nsc.settings
11 11
  * Represents a single Scala version in a manner that
12 12
  * supports easy comparison and sorting.
13 13
  */
14  
-abstract class ScalaVersion extends Ordered[ScalaVersion] {
  14
+sealed abstract class ScalaVersion extends Ordered[ScalaVersion] {
15 15
   def unparse: String
16 16
 }
17 17
 
8  src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
@@ -79,7 +79,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
79 79
       def chainBefore(next: Tree)(casegen: Casegen): Tree
80 80
     }
81 81
 
82  
-    trait NoNewBinders extends TreeMaker {
  82
+    sealed trait NoNewBinders extends TreeMaker {
83 83
       protected val localSubstitution: Substitution = EmptySubstitution
84 84
     }
85 85
 
@@ -105,12 +105,12 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
105 105
       override def toString = "S"+ localSubstitution
106 106
     }
107 107
 
108  
-    abstract class FunTreeMaker extends TreeMaker {
  108
+    sealed abstract class FunTreeMaker extends TreeMaker {
109 109
       val nextBinder: Symbol
110 110
       def pos = nextBinder.pos
111 111
     }
112 112
 
113  
-    abstract class CondTreeMaker extends FunTreeMaker {
  113
+    sealed abstract class CondTreeMaker extends FunTreeMaker {
114 114
       val prevBinder: Symbol
115 115
       val nextBinderTp: Type
116 116
       val cond: Tree
@@ -126,7 +126,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
126 126
     // unless we're optimizing, emit local variable bindings for all subpatterns of extractor/case class patterns
127 127
     protected val debugInfoEmitVars = !settings.optimise.value
128 128
 
129  
-    trait PreserveSubPatBinders extends TreeMaker {
  129
+    sealed trait PreserveSubPatBinders extends TreeMaker {
130 130
       val subPatBinders: List[Symbol]
131 131
       val subPatRefs: List[Tree]
132 132
       val ignoredSubPatBinders: Set[Symbol]
4  src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
@@ -21,13 +21,13 @@ trait ContextErrors {
21 21
   import global._
22 22
   import definitions._
23 23
 
24  
-  abstract class AbsTypeError extends Throwable {
  24
+  sealed abstract class AbsTypeError extends Throwable {
25 25
     def errPos: Position
26 26
     def errMsg: String
27 27
     override def toString() = "[Type error at:" + errPos + "] " + errMsg
28 28
   }
29 29
 
30  
-  abstract class TreeTypeError extends AbsTypeError {
  30
+  sealed abstract class TreeTypeError extends AbsTypeError {
31 31
     def underlyingTree: Tree
32 32
     def errPos = underlyingTree.pos
33 33
   }
16  src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -259,7 +259,7 @@ trait MethodSynthesis {
259 259
      *  So it's important that creating an instance of Derived does not have a side effect,
260 260
      *  or if it has a side effect, control that it is done only once.
261 261
      */
262  
-    trait Derived {
  262
+    sealed trait Derived {
263 263
 
264 264
       /** The tree from which we are deriving a synthetic member. Typically, that's
265 265
        *  given as an argument of the instance. */
@@ -288,7 +288,7 @@ trait MethodSynthesis {
288 288
       def derivedTree: Tree
289 289
     }
290 290
 
291  
-    trait DerivedFromMemberDef extends Derived {
  291
+    sealed trait DerivedFromMemberDef extends Derived {
292 292
       def tree: MemberDef
293 293
       def enclClass: Symbol
294 294
 
@@ -297,12 +297,12 @@ trait MethodSynthesis {
297 297
       final def basisSym           = tree.symbol
298 298
     }
299 299
 
300  
-    trait DerivedFromClassDef extends DerivedFromMemberDef {
  300
+    sealed trait DerivedFromClassDef extends DerivedFromMemberDef {
301 301
       def tree: ClassDef
302 302
       final def enclClass = basisSym.owner.enclClass
303 303
     }
304 304
 
305  
-    trait DerivedFromValDef extends DerivedFromMemberDef {
  305
+    sealed trait DerivedFromValDef extends DerivedFromMemberDef {
306 306
       def tree: ValDef
307 307
       final def enclClass = basisSym.enclClass
308 308
 
@@ -341,10 +341,10 @@ trait MethodSynthesis {
341 341
         logDerived(derivedTree)
342 342
       }
343 343
     }
344  
-    trait DerivedGetter extends DerivedFromValDef {
  344
+    sealed trait DerivedGetter extends DerivedFromValDef {
345 345
       // TODO
346 346
     }
347  
-    trait DerivedSetter extends DerivedFromValDef {
  347
+    sealed trait DerivedSetter extends DerivedFromValDef {
348 348
       override def isSetter = true
349 349
       private def setterParam = derivedSym.paramss match {
350 350
         case (p :: Nil) :: _  => p
@@ -378,7 +378,7 @@ trait MethodSynthesis {
378 378
       def name: TermName               = tree.name.toTermName
379 379
     }
380 380
 
381  
-    abstract class BaseGetter(tree: ValDef) extends DerivedGetter {
  381
+    sealed abstract class BaseGetter(tree: ValDef) extends DerivedGetter {
382 382
       def name       = tree.name
383 383
       def category   = GetterTargetClass
384 384
       def flagsMask  = GetterFlags
@@ -510,7 +510,7 @@ trait MethodSynthesis {
510 510
       def flagsExtra = 0
511 511
       override def derivedSym = enclClass.info decl name
512 512
     }
513  
-    trait AnyBeanGetter extends BeanAccessor with DerivedGetter {
  513
+    sealed trait AnyBeanGetter extends BeanAccessor with DerivedGetter {
514 514
       def category = BeanGetterTargetClass
515 515
       override def validate() {
516 516
         if (derivedSym == NoSymbol) {
10  src/library/scala/xml/dtd/Decl.scala
@@ -12,9 +12,9 @@ package dtd
12 12
 
13 13
 import Utility.sbToString
14 14
 
15  
-abstract class Decl
  15
+sealed abstract class Decl
16 16
 
17  
-abstract class MarkupDecl extends Decl {
  17
+sealed abstract class MarkupDecl extends Decl {
18 18
   def buildString(sb: StringBuilder): StringBuilder
19 19
 }
20 20
 
@@ -52,7 +52,7 @@ case class AttrDecl(name: String, tpe: String, default: DefaultDecl) {
52 52
 }
53 53
 
54 54
 /** an entity declaration */
55  
-abstract class EntityDecl extends MarkupDecl
  55
+sealed abstract class EntityDecl extends MarkupDecl
56 56
 
57 57
 /** a parsed general entity declaration */
58 58
 case class ParsedEntityDecl(name: String, entdef: EntityDef) extends EntityDecl {
@@ -85,7 +85,7 @@ case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl {
85 85
   }
86 86
 }
87 87
 
88  
-abstract class EntityDef {
  88
+sealed abstract class EntityDef {
89 89
   def buildString(sb: StringBuilder): StringBuilder
90 90
 }
91 91
 
@@ -133,7 +133,7 @@ case class PEReference(ent:String) extends MarkupDecl {
133 133
 
134 134
 // default declarations for attributes
135 135
 
136  
-abstract class DefaultDecl {
  136
+sealed abstract class DefaultDecl {
137 137
   override def toString(): String
138 138
   def buildString(sb: StringBuilder): StringBuilder
139 139
 }
2  src/library/scala/xml/dtd/ExternalID.scala
@@ -15,7 +15,7 @@ package dtd
15 15
  *
16 16
  *  @author Burak Emir
17 17
  */
18  
-abstract class ExternalID extends parsing.TokenTests {
  18
+sealed abstract class ExternalID extends parsing.TokenTests {
19 19
   def quoted(s: String) = {
20 20
     val c = if (s contains '"') '\'' else '"'
21 21
     c + s + c
2  src/reflect/scala/reflect/internal/AnnotationInfos.scala
@@ -73,7 +73,7 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
73 73
    *  - arrays of constants
74 74
    *  - or nested classfile annotations
75 75
    */
76  
-  abstract class ClassfileAnnotArg extends Product
  76
+  sealed abstract class ClassfileAnnotArg extends Product
77 77
   implicit val JavaArgumentTag = ClassTag[ClassfileAnnotArg](classOf[ClassfileAnnotArg])
78 78
   case object UnmappableAnnotArg extends ClassfileAnnotArg
79 79
 
2  src/reflect/scala/reflect/internal/Symbols.scala
@@ -3433,7 +3433,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
3433 3433
   }
3434 3434
 
3435 3435
   /** A class for type histories */
3436  
-  private sealed case class TypeHistory(var validFrom: Period, info: Type, prev: TypeHistory) {
  3436
+  private case class TypeHistory(var validFrom: Period, info: Type, prev: TypeHistory) {
3437 3437
     assert((prev eq null) || phaseId(validFrom) > phaseId(prev.validFrom), this)
3438 3438
     assert(validFrom != NoPeriod, this)
3439 3439
 
12  src/reflect/scala/reflect/internal/util/Statistics.scala
@@ -133,6 +133,12 @@ quant)
133 133
       if (this.value < that.value) -1
134 134
       else if (this.value > that.value) 1
135 135
       else 0
  136
+    override def equals(that: Any): Boolean =
  137
+      that match {
  138
+        case that: Counter => (this compare that) == 0
  139
+        case _ => false
  140
+      }
  141
+    override def hashCode = value
136 142
     override def toString = value.toString
137 143
   }
138 144
 
@@ -184,6 +190,12 @@ quant)
184 190
       if (this.specificNanos < that.specificNanos) -1
185 191
       else if (this.specificNanos > that.specificNanos) 1
186 192
       else 0
  193
+    override def equals(that: Any): Boolean =
  194
+      that match {
  195
+        case that: StackableTimer => (this compare that) == 0
  196
+        case _ => false
  197
+      }
  198
+    override def hashCode = specificNanos.##
187 199
     override def toString = s"${super.toString} aggregate, ${show(specificNanos)} specific"
188 200
   }
189 201
 
4  src/scaladoc/scala/tools/nsc/doc/model/diagram/Diagram.scala
@@ -10,7 +10,7 @@ import model._
10 10
  *  @author Damien Obrist
11 11
  *  @author Vlad Ureche
12 12
  */
13  
-abstract class Diagram {
  13
+sealed abstract class Diagram {
14 14
   def nodes: List[Node]
15 15
   def edges: List[(Node, List[Node])]
16 16
   def isContentDiagram = false     // Implemented by ContentDiagram
@@ -44,7 +44,7 @@ trait DepthInfo {
44 44
   def maxDepth: Int
45 45
 }
46 46
 
47  
-abstract class Node {
  47
+sealed abstract class Node {
48 48
   def name = tpe.name
49 49
   def tpe: TypeEntity
50 50
   def tpl: Option[TemplateEntity]
1  test/files/codelib/.gitignore
... ...
@@ -0,0 +1 @@
  1
+code.jar
8  test/files/lib/.gitignore
... ...
@@ -0,0 +1,8 @@
  1
+annotations.jar
  2
+enums.jar
  3
+genericNest.jar
  4
+javac-artifacts.jar
  5
+jsoup-1.3.1.jar
  6
+methvsfield.jar
  7
+nest.jar
  8
+scalacheck.jar
1  test/files/speclib/.gitignore
... ...
@@ -0,0 +1 @@
  1
+instrumented.jar
1  tools/.gitignore
... ...
@@ -0,0 +1 @@
  1
+push.jar
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.