Skip to content

Commit 3c44403

Browse files
Add explicit return types to public members
Using a published local version of RscCompat
1 parent 221bde9 commit 3c44403

File tree

256 files changed

+3617
-3608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+3617
-3608
lines changed

compiler/sjs/backend/sjs/JSCodeGen.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ class JSCodeGen()(implicit ctx: Context) {
17041704
nme.UNARY_! -> js.JSUnaryOp.!
17051705
)
17061706

1707-
def unapply(name: Names.TermName): Option[js.JSUnaryOp.Code] =
1707+
def unapply(name: TermName): Option[js.JSUnaryOp.Code] =
17081708
map.get(name)
17091709
}
17101710

@@ -1732,7 +1732,7 @@ class JSCodeGen()(implicit ctx: Context) {
17321732
nme.ZOR -> js.JSBinaryOp.||
17331733
)
17341734

1735-
def unapply(name: Names.TermName): Option[js.JSBinaryOp.Code] =
1735+
def unapply(name: TermName): Option[js.JSBinaryOp.Code] =
17361736
map.get(name)
17371737
}
17381738

compiler/sjs/backend/sjs/JSEncoding.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ object JSEncoding {
3939
private final val ScalaJSEnvironmentName = "ScalaJS"
4040

4141
implicit class SymOps(val self: Symbol) extends AnyVal {
42-
def unexpandedName(implicit ctx: Context): Names.Name =
42+
def unexpandedName(implicit ctx: Context): Name =
4343
self.name.unexpandedName
4444
}
4545

46-
implicit class MyNameOps(val self: Names.Name) extends AnyVal {
46+
implicit class MyNameOps(val self: Name) extends AnyVal {
4747
def decoded: String = self.decode.toString
4848
}
4949

compiler/sjs/backend/sjs/JSPositions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.scalajs.core.ir
1111
class JSPositions()(implicit ctx: Context) {
1212

1313
/** Implicit conversion from dotty Position to ir.Position. */
14-
implicit def pos2irPos(pos: Positions.Position): ir.Position = {
14+
implicit def pos2irPos(pos: Position): ir.Position = {
1515
if (!pos.exists) ir.Position.NoPosition
1616
else {
1717
val source = pos2irPosCache.toIRSource(ctx.compilationUnit.source)
@@ -23,7 +23,7 @@ class JSPositions()(implicit ctx: Context) {
2323

2424
/** Implicitly materializes an ir.Position from an implicit dotty Position. */
2525
implicit def implicitPos2irPos(
26-
implicit pos: Positions.Position): ir.Position = {
26+
implicit pos: Position): ir.Position = {
2727
pos2irPos(pos)
2828
}
2929

compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CollectEntryPoints extends MiniPhase {
3131
}
3232

3333
object CollectEntryPoints{
34-
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context) = {
34+
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = {
3535
(sym.name == nme.main) && (sym.info match {
3636
case r@MethodTpe(_, List(defn.ArrayOf(t)), _) =>
3737
(t.widenDealias =:= defn.StringType) && (

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import tpd._
2828
import scala.tools.asm
2929
import StdNames.{nme, str}
3030
import NameKinds.{DefaultGetterName, ExpandedName}
31-
31+
import Names.TermName
3232

3333
class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit ctx: Context) extends BackendInterface{
3434
import Symbols.{toDenot, toClassDenot}
@@ -76,7 +76,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
7676
type LabelDef = tpd.DefDef
7777
type Closure = tpd.Closure
7878

79-
val NoSymbol = Symbols.NoSymbol
79+
val NoSymbol: Symbols.NoSymbol.type = Symbols.NoSymbol
8080
val NoPosition: Position = Positions.NoPosition
8181
val EmptyTree: Tree = tpd.EmptyTree
8282

@@ -104,11 +104,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
104104
val nme_EQEQ_LOCAL_VAR: Name = StdNames.nme.EQEQ_LOCAL_VAR
105105

106106
// require LambdaMetafactory: scalac uses getClassIfDefined, but we need those always.
107-
override lazy val LambdaMetaFactory = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
108-
override lazy val MethodHandle = ctx.requiredClass("java.lang.invoke.MethodHandle")
107+
override lazy val LambdaMetaFactory: ClassSymbol = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
108+
override lazy val MethodHandle: ClassSymbol = ctx.requiredClass("java.lang.invoke.MethodHandle")
109109

110110
val nme_valueOf: Name = StdNames.nme.valueOf
111-
val nme_apply = StdNames.nme.apply
111+
val nme_apply: TermName = StdNames.nme.apply
112112
val NothingClass: Symbol = defn.NothingClass
113113
val NullClass: Symbol = defn.NullClass
114114
val ObjectClass: Symbol = defn.ObjectClass
@@ -128,7 +128,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
128128
val LongClass: Symbol = defn.LongClass
129129
val FloatClass: Symbol = defn.FloatClass
130130
val DoubleClass: Symbol = defn.DoubleClass
131-
def isArrayClone(tree: Tree) = tree match {
131+
def isArrayClone(tree: Tree): Boolean = tree match {
132132
case Select(qual, StdNames.nme.clone_) if qual.tpe.widen.isInstanceOf[JavaArrayType] => true
133133
case _ => false
134134
}
@@ -146,19 +146,19 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
146146
val String_valueOf: Symbol = defn.String_valueOf_Object
147147
lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf)
148148

149-
lazy val AnnotationRetentionAttr = ctx.requiredClass("java.lang.annotation.Retention")
150-
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
151-
lazy val AnnotationRetentionClassAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
152-
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
153-
lazy val JavaAnnotationClass = ctx.requiredClass("java.lang.annotation.Annotation")
149+
lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
150+
lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
151+
lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
152+
lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
153+
lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
154154

155155
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def?
156156
(x, Erasure.Boxing.boxMethod(x.asClass))
157157
}.toMap
158158
def unboxMethods: Map[Symbol, Symbol] =
159159
defn.ScalaValueClasses().map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap
160160

161-
override def isSyntheticArrayConstructor(s: Symbol) = {
161+
override def isSyntheticArrayConstructor(s: Symbol): Boolean = {
162162
s eq defn.newArrayMethod
163163
}
164164

@@ -309,7 +309,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
309309
}
310310

311311
override def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
312-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
312+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
313313
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
314314
val typ = annot.atp
315315
val assocs = annot.assocs
@@ -326,7 +326,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
326326
}
327327

328328
override def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
329-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
329+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
330330
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
331331
val typ = annot.atp
332332
val assocs = annot.assocs
@@ -336,7 +336,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
336336
}
337337

338338
override def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
339-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
339+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
340340
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
341341
val typ = annot.atp
342342
val assocs = annot.assocs
@@ -392,7 +392,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
392392

393393
def emitAsmp: Option[String] = None
394394

395-
def shouldEmitJumpAfterLabels = true
395+
def shouldEmitJumpAfterLabels: Boolean = true
396396

397397
def dumpClasses: Option[String] =
398398
if (ctx.settings.Ydumpclasses.isDefault) None
@@ -420,7 +420,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
420420

421421
val MODULE_INSTANCE_FIELD: String = str.MODULE_INSTANCE_FIELD
422422

423-
def dropModule(str: String) =
423+
def dropModule(str: String): String =
424424
if (!str.isEmpty && str.last == '$') str.take(str.length - 1) else str
425425

426426
def newTermName(prefix: String): Name = prefix.toTermName
@@ -471,7 +471,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
471471
}
472472

473473
// todo: remove
474-
def isMaybeBoxed(sym: Symbol) = {
474+
def isMaybeBoxed(sym: Symbol): Boolean = {
475475
(sym == ObjectClass) ||
476476
(sym == JavaSerializableClass) ||
477477
(sym == defn.ComparableClass) ||
@@ -1047,13 +1047,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10471047

10481048
// todo: this product1s should also eventually become name-based pattn matching
10491049
object Literal extends LiteralDeconstructor {
1050-
def get = field.const
1050+
def get: Constant = field.const
10511051
}
10521052

10531053
object Throw extends ThrowDeconstructor {
1054-
def get = field.args.head
1054+
def get: Tree = field.args.head
10551055

1056-
override def unapply(s: Throw): DottyBackendInterface.this.Throw.type = {
1056+
override def unapply(s: Throw): Throw.type = {
10571057
if (s.fun.symbol eq defn.throwMethod) {
10581058
field = s
10591059
} else {
@@ -1064,11 +1064,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10641064
}
10651065

10661066
object New extends NewDeconstructor {
1067-
def get = field.tpt.tpe
1067+
def get: Type = field.tpt.tpe
10681068
}
10691069

10701070
object This extends ThisDeconstructor {
1071-
def get = field.qual.name
1071+
def get: Name = field.qual.name
10721072
def apply(s: Symbol): This = tpd.This(s.asClass)
10731073
}
10741074

@@ -1088,15 +1088,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10881088
}
10891089

10901090
object Ident extends IdentDeconstructor {
1091-
def get = field.name
1091+
def get: Name = field.name
10921092
}
10931093

10941094
object Alternative extends AlternativeDeconstructor {
1095-
def get = field.trees
1095+
def get: List[Tree] = field.trees
10961096
}
10971097

10981098
object Constant extends ConstantDeconstructor {
1099-
def get = field.value
1099+
def get: Any = field.value
11001100
}
11011101
object ThrownException extends ThrownException {
11021102
def unapply(a: Annotation): Option[Symbol] = None // todo
@@ -1113,7 +1113,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11131113
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
11141114
def _3: Tree = field.rhs
11151115

1116-
override def unapply(s: LabelDef): DottyBackendInterface.this.LabelDef.type = {
1116+
override def unapply(s: LabelDef): LabelDef.type = {
11171117
if (s.symbol is Flags.Label) this.field = s
11181118
else this.field = null
11191119
this
@@ -1191,9 +1191,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11911191
}
11921192

11931193
object Closure extends ClosureDeconstructor {
1194-
def _1 = field.env
1195-
def _2 = field.meth
1196-
def _3 = {
1194+
def _1: List[Tree] = field.env
1195+
def _2: Tree = field.meth
1196+
def _3: Symbol = {
11971197
val t = field.tpt.tpe.typeSymbol
11981198
if (t.exists) t
11991199
else {
@@ -1206,5 +1206,5 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
12061206
}
12071207
}
12081208

1209-
def currentUnit = ctx.compilationUnit
1209+
def currentUnit: CompilationUnit = ctx.compilationUnit
12101210
}

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import scala.tools.asm.CustomAttr
1010
import scala.tools.nsc.backend.jvm._
1111
import dotty.tools.dotc.transform.SymUtils._
1212
import dotty.tools.dotc.interfaces
13+
import dotty.tools.dotc.util.SourceFile
1314
import java.util.Optional
1415

1516
import dotty.tools.dotc.core._
@@ -31,10 +32,10 @@ import dotty.tools.io._
3132
class GenBCode extends Phase {
3233
def phaseName: String = GenBCode.name
3334
private val entryPoints = new mutable.HashSet[Symbol]()
34-
def registerEntryPoint(sym: Symbol) = entryPoints += sym
35+
def registerEntryPoint(sym: Symbol): mutable.HashSet[Symbol] = entryPoints += sym
3536

3637
private val superCallsMap = newMutableSymbolMap[Set[ClassSymbol]]
37-
def registerSuperCall(sym: Symbol, calls: ClassSymbol) = {
38+
def registerSuperCall(sym: Symbol, calls: ClassSymbol): Unit = {
3839
val old = superCallsMap.getOrElse(sym, Set.empty)
3940
superCallsMap.update(sym, old + calls)
4041
}
@@ -53,7 +54,7 @@ class GenBCode extends Phase {
5354
entryPoints.clear()
5455
}
5556

56-
override def runOn(units: List[CompilationUnit])(implicit ctx: Context) = {
57+
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
5758
try super.runOn(units)
5859
finally myOutput match {
5960
case jar: JarArchive =>
@@ -71,7 +72,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
7172

7273
var tree: Tree = _
7374

74-
val sourceFile = ctx.compilationUnit.source
75+
val sourceFile: SourceFile = ctx.compilationUnit.source
7576

7677
/** Convert a `dotty.tools.io.AbstractFile` into a
7778
* `dotty.tools.dotc.interfaces.AbstractFile`.
@@ -94,7 +95,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
9495
/* ---------------- q1 ---------------- */
9596

9697
case class Item1(arrivalPos: Int, cd: TypeDef, cunit: CompilationUnit) {
97-
def isPoison = { arrivalPos == Int.MaxValue }
98+
def isPoison: Boolean = { arrivalPos == Int.MaxValue }
9899
}
99100
private val poison1 = Item1(Int.MaxValue, null, ctx.compilationUnit)
100101
private val q1 = new java.util.LinkedList[Item1]
@@ -107,7 +108,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
107108
case class Item2(arrivalPos: Int,
108109
mirror: SubItem2,
109110
plain: SubItem2) {
110-
def isPoison = { arrivalPos == Int.MaxValue }
111+
def isPoison: Boolean = { arrivalPos == Int.MaxValue }
111112
}
112113

113114
private val poison2 = Item2(Int.MaxValue, null, null)
@@ -132,7 +133,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
132133
mirror: SubItem3,
133134
plain: SubItem3) {
134135

135-
def isPoison = { arrivalPos == Int.MaxValue }
136+
def isPoison: Boolean = { arrivalPos == Int.MaxValue }
136137
}
137138
private val i3comparator = new java.util.Comparator[Item3] {
138139
override def compare(a: Item3, b: Item3) = {
@@ -191,7 +192,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
191192
* enqueues them in queue-2.
192193
*
193194
*/
194-
def visit(item: Item1) = {
195+
def visit(item: Item1): Boolean = {
195196
val Item1(arrivalPos, cd, cunit) = item
196197
val claszSymbol = cd.symbol
197198

@@ -350,7 +351,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
350351

351352
} // end of class BCodePhase.Worker2
352353

353-
var arrivalPos = 0
354+
var arrivalPos: Int = 0
354355

355356
/*
356357
* A run of the BCodePhase phase comprises:
@@ -363,7 +364,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
363364
* (c) tear down (closing the classfile-writer and clearing maps)
364365
*
365366
*/
366-
def run(t: Tree) = {
367+
def run(t: Tree): Unit = {
367368
this.tree = t
368369

369370
// val bcodeStart = Statistics.startTimer(BackendStats.bcodeTimer)

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import dotty.tools.dotc.transform.SymUtils._
1212

1313
class CompilationUnit(val source: SourceFile) {
1414

15-
override def toString = source.toString
15+
override def toString: String = source.toString
1616

1717
var untpdTree: untpd.Tree = untpd.EmptyTree
1818

1919
var tpdTree: tpd.Tree = tpd.EmptyTree
2020

21-
def isJava = source.file.name.endsWith(".java")
21+
def isJava: Boolean = source.file.name.endsWith(".java")
2222

2323
/** Pickled TASTY binaries, indexed by class. */
2424
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
@@ -29,7 +29,7 @@ class CompilationUnit(val source: SourceFile) {
2929
var containsQuotesOrSplices: Boolean = false
3030

3131
/** A structure containing a temporary map for generating inline accessors */
32-
val inlineAccessors = new InlineAccessors
32+
val inlineAccessors: InlineAccessors = new InlineAccessors
3333
}
3434

3535
object CompilationUnit {

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class Compiler {
118118
List(new GenBCode) :: // Generate JVM bytecode
119119
Nil
120120

121-
var runId = 1
122-
def nextRunId = {
121+
var runId: Int = 1
122+
def nextRunId: Int = {
123123
runId += 1; runId
124124
}
125125

0 commit comments

Comments
 (0)