Skip to content

Commit 786e6da

Browse files
Merge pull request #5203 from OlivierBlanvillain/scalafix
Add explicit return types to public members
2 parents d79b43f + c54153a commit 786e6da

File tree

293 files changed

+3797
-4290
lines changed

Some content is hidden

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

293 files changed

+3797
-4290
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: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,15 @@ import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Types
66
import dotty.tools.dotc.transform.MegaPhase._
77
import dotty.tools.dotc.ast.tpd
8-
import dotty.tools.dotc
9-
import dotty.tools.dotc.core.Flags.FlagSet
10-
import dotty.tools.dotc.transform.Erasure
11-
import dotty.tools.dotc.transform.SymUtils._
12-
import java.io.{File => JFile}
8+
import java.io.{File => _}
139

14-
import scala.collection.generic.Clearable
15-
import scala.collection.mutable
16-
import scala.reflect.ClassTag
17-
import dotty.tools.io.{Directory, PlainDirectory, AbstractFile}
18-
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
19-
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
2010
import dotty.tools.dotc.core._
21-
import Periods._
2211
import SymDenotations._
2312
import Contexts._
2413
import Types._
2514
import Symbols._
26-
import Denotations._
27-
import Phases._
28-
import java.lang.AssertionError
2915
import dotty.tools.dotc.util.Positions.Position
3016
import Decorators._
31-
import tpd._
3217
import StdNames.nme
3318

3419
/**
@@ -46,7 +31,7 @@ class CollectEntryPoints extends MiniPhase {
4631
}
4732

4833
object CollectEntryPoints{
49-
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context) = {
34+
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = {
5035
(sym.name == nme.main) && (sym.info match {
5136
case r@MethodTpe(_, List(defn.ArrayOf(t)), _) =>
5237
(t.widenDealias =:= defn.StringType) && (
@@ -56,7 +41,6 @@ object CollectEntryPoints{
5641
}
5742

5843
def isJavaEntryPoint(sym: Symbol)(implicit ctx: Context): Boolean = {
59-
import Types.MethodType
6044
val d = ctx.definitions
6145
val StringType = d.StringType
6246
// The given class has a main method.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.backend.jvm
22

33
import dotty.tools.dotc.ast.tpd
4-
import dotty.tools.dotc.ast.Trees._
54
import dotty.tools.dotc.core.Contexts.Context
65
import dotty.tools.dotc.core.Symbols._
76
import dotty.tools.dotc.core.Flags.Trait

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

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,29 @@ import dotty.tools.dotc
66
import dotty.tools.dotc.core.Flags.FlagSet
77
import dotty.tools.dotc.transform.{Erasure, GenericSignatures}
88
import dotty.tools.dotc.transform.SymUtils._
9-
import java.io.{File => JFile}
9+
import java.io.{File => _}
1010

1111
import scala.collection.generic.Clearable
1212
import scala.collection.mutable
1313
import scala.reflect.ClassTag
1414
import scala.reflect.internal.util.WeakHashSet
15-
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory}
16-
import scala.tools.asm.{AnnotationVisitor, ClassVisitor, FieldVisitor, MethodVisitor}
15+
import dotty.tools.io.AbstractFile
16+
import scala.tools.asm.AnnotationVisitor
1717
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
1818
import dotty.tools.dotc.core._
19-
import Periods._
20-
import SymDenotations._
2119
import Contexts._
2220
import Types._
2321
import Symbols._
24-
import Denotations._
2522
import Phases._
26-
import java.lang.AssertionError
2723

28-
import dotty.tools.dotc.util.{DotClass, Positions}
24+
import dotty.tools.dotc.util.Positions
2925
import Decorators._
3026
import tpd._
3127

3228
import scala.tools.asm
3329
import StdNames.{nme, str}
34-
import NameOps._
3530
import NameKinds.{DefaultGetterName, ExpandedName}
36-
import dotty.tools.dotc.core
37-
import dotty.tools.dotc.core.Names.TypeName
38-
39-
import scala.annotation.tailrec
31+
import Names.TermName
4032

4133
class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit ctx: Context) extends BackendInterface{
4234
import Symbols.{toDenot, toClassDenot}
@@ -84,7 +76,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
8476
type LabelDef = tpd.DefDef
8577
type Closure = tpd.Closure
8678

87-
val NoSymbol = Symbols.NoSymbol
79+
val NoSymbol: Symbol = Symbols.NoSymbol
8880
val NoPosition: Position = Positions.NoPosition
8981
val EmptyTree: Tree = tpd.EmptyTree
9082

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

114106
// require LambdaMetafactory: scalac uses getClassIfDefined, but we need those always.
115-
override lazy val LambdaMetaFactory = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
116-
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")
117109

118110
val nme_valueOf: Name = StdNames.nme.valueOf
119-
val nme_apply = StdNames.nme.apply
111+
val nme_apply: TermName = StdNames.nme.apply
120112
val NothingClass: Symbol = defn.NothingClass
121113
val NullClass: Symbol = defn.NullClass
122114
val ObjectClass: Symbol = defn.ObjectClass
@@ -136,7 +128,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
136128
val LongClass: Symbol = defn.LongClass
137129
val FloatClass: Symbol = defn.FloatClass
138130
val DoubleClass: Symbol = defn.DoubleClass
139-
def isArrayClone(tree: Tree) = tree match {
131+
def isArrayClone(tree: Tree): Boolean = tree match {
140132
case Select(qual, StdNames.nme.clone_) if qual.tpe.widen.isInstanceOf[JavaArrayType] => true
141133
case _ => false
142134
}
@@ -154,19 +146,19 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
154146
val String_valueOf: Symbol = defn.String_valueOf_Object
155147
lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf)
156148

157-
lazy val AnnotationRetentionAttr = ctx.requiredClass("java.lang.annotation.Retention")
158-
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
159-
lazy val AnnotationRetentionClassAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
160-
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
161-
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")
162154

163155
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def?
164156
(x, Erasure.Boxing.boxMethod(x.asClass))
165157
}.toMap
166158
def unboxMethods: Map[Symbol, Symbol] =
167159
defn.ScalaValueClasses().map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap
168160

169-
override def isSyntheticArrayConstructor(s: Symbol) = {
161+
override def isSyntheticArrayConstructor(s: Symbol): Boolean = {
170162
s eq defn.newArrayMethod
171163
}
172164

@@ -317,7 +309,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
317309
}
318310

319311
override def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
320-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
312+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
321313
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
322314
val typ = annot.atp
323315
val assocs = annot.assocs
@@ -334,7 +326,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
334326
}
335327

336328
override def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
337-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
329+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
338330
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
339331
val typ = annot.atp
340332
val assocs = annot.assocs
@@ -344,7 +336,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
344336
}
345337

346338
override def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
347-
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
339+
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
348340
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
349341
val typ = annot.atp
350342
val assocs = annot.assocs
@@ -400,7 +392,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
400392

401393
def emitAsmp: Option[String] = None
402394

403-
def shouldEmitJumpAfterLabels = true
395+
def shouldEmitJumpAfterLabels: Boolean = true
404396

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

429421
val MODULE_INSTANCE_FIELD: String = str.MODULE_INSTANCE_FIELD
430422

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

434426
def newTermName(prefix: String): Name = prefix.toTermName
@@ -479,7 +471,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
479471
}
480472

481473
// todo: remove
482-
def isMaybeBoxed(sym: Symbol) = {
474+
def isMaybeBoxed(sym: Symbol): Boolean = {
483475
(sym == ObjectClass) ||
484476
(sym == JavaSerializableClass) ||
485477
(sym == defn.ComparableClass) ||
@@ -1055,13 +1047,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10551047

10561048
// todo: this product1s should also eventually become name-based pattn matching
10571049
object Literal extends LiteralDeconstructor {
1058-
def get = field.const
1050+
def get: Constant = field.const
10591051
}
10601052

10611053
object Throw extends ThrowDeconstructor {
1062-
def get = field.args.head
1054+
def get: Tree = field.args.head
10631055

1064-
override def unapply(s: Throw): DottyBackendInterface.this.Throw.type = {
1056+
override def unapply(s: Throw): Throw.type = {
10651057
if (s.fun.symbol eq defn.throwMethod) {
10661058
field = s
10671059
} else {
@@ -1072,11 +1064,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10721064
}
10731065

10741066
object New extends NewDeconstructor {
1075-
def get = field.tpt.tpe
1067+
def get: Type = field.tpt.tpe
10761068
}
10771069

10781070
object This extends ThisDeconstructor {
1079-
def get = field.qual.name
1071+
def get: Name = field.qual.name
10801072
def apply(s: Symbol): This = tpd.This(s.asClass)
10811073
}
10821074

@@ -1096,15 +1088,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
10961088
}
10971089

10981090
object Ident extends IdentDeconstructor {
1099-
def get = field.name
1091+
def get: Name = field.name
11001092
}
11011093

11021094
object Alternative extends AlternativeDeconstructor {
1103-
def get = field.trees
1095+
def get: List[Tree] = field.trees
11041096
}
11051097

11061098
object Constant extends ConstantDeconstructor {
1107-
def get = field.value
1099+
def get: Any = field.value
11081100
}
11091101
object ThrownException extends ThrownException {
11101102
def unapply(a: Annotation): Option[Symbol] = None // todo
@@ -1121,7 +1113,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11211113
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
11221114
def _3: Tree = field.rhs
11231115

1124-
override def unapply(s: LabelDef): DottyBackendInterface.this.LabelDef.type = {
1116+
override def unapply(s: LabelDef): LabelDef.type = {
11251117
if (s.symbol is Flags.Label) this.field = s
11261118
else this.field = null
11271119
this
@@ -1199,9 +1191,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11991191
}
12001192

12011193
object Closure extends ClosureDeconstructor {
1202-
def _1 = field.env
1203-
def _2 = field.meth
1204-
def _3 = {
1194+
def _1: List[Tree] = field.env
1195+
def _2: Tree = field.meth
1196+
def _3: Symbol = {
12051197
val t = field.tpt.tpe.typeSymbol
12061198
if (t.exists) t
12071199
else {
@@ -1214,5 +1206,5 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
12141206
}
12151207
}
12161208

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

0 commit comments

Comments
 (0)