Skip to content

Commit 1efead3

Browse files
committed
Remove unneeded abstractions
1 parent ff6e675 commit 1efead3

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,8 +2713,8 @@ object Types {
27132713

27142714
def companion: MethodTypeCompanion
27152715

2716-
final override def isJavaMethod: Boolean = companion.isJava
2717-
final override def isImplicitMethod: Boolean = companion.isImplicit
2716+
final override def isJavaMethod: Boolean = companion eq JavaMethodType
2717+
final override def isImplicitMethod: Boolean = companion eq ImplicitMethodType
27182718

27192719
val paramInfos = paramInfosExp(this)
27202720
val resType = resultTypeExp(this)
@@ -2796,9 +2796,6 @@ object Types {
27962796

27972797
abstract class MethodTypeCompanion extends TermLambdaCompanion[MethodType] { self =>
27982798

2799-
def isJava: Boolean = false
2800-
def isImplicit: Boolean = false
2801-
28022799
/** Produce method type from parameter symbols, with special mappings for repeated
28032800
* and inline parameters:
28042801
* - replace @repeated annotations on Seq or Array types by <repeated> types
@@ -2842,21 +2839,9 @@ object Types {
28422839
}
28432840
}
28442841

2845-
object MethodType extends MethodTypeCompanion {
2846-
def withKind(isJava: Boolean = false, isImplicit: Boolean = false): MethodTypeCompanion = {
2847-
if (isJava) JavaMethodType
2848-
else if (isImplicit) ImplicitMethodType
2849-
else MethodType
2850-
}
2851-
}
2852-
2853-
object JavaMethodType extends MethodTypeCompanion {
2854-
override def isJava: Boolean = true
2855-
}
2856-
2857-
object ImplicitMethodType extends MethodTypeCompanion {
2858-
override def isImplicit: Boolean = true
2859-
}
2842+
object MethodType extends MethodTypeCompanion
2843+
object JavaMethodType extends MethodTypeCompanion
2844+
object ImplicitMethodType extends MethodTypeCompanion
28602845

28612846
/** A ternary extractor for MethodType */
28622847
object MethodTpe {

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
774774
def isImplicit =
775775
tag == IMPLICITMETHODtpe ||
776776
params.nonEmpty && (params.head is Implicit)
777-
MethodType.withKind(isImplicit = isImplicit).fromSymbols(params, restpe)
777+
val maker = if (isImplicit) ImplicitMethodType else MethodType
778+
maker.fromSymbols(params, restpe)
778779
case POLYtpe =>
779780
val restpe = readTypeRef()
780781
val typeParams = until(end, readSymbolRef)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ trait NamerContextOps { this: Context =>
107107
def methodType(typeParams: List[Symbol], valueParamss: List[List[Symbol]], resultType: Type, isJava: Boolean = false)(implicit ctx: Context): Type = {
108108
val monotpe =
109109
(valueParamss :\ resultType) { (params, resultType) =>
110-
val isImplicit = params.nonEmpty && (params.head is Implicit)
110+
val make =
111+
if (params.nonEmpty && (params.head is Implicit)) ImplicitMethodType
112+
else if (isJava) JavaMethodType
113+
else MethodType
111114
if (isJava)
112115
for (param <- params)
113116
if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType
114-
MethodType.withKind(isJava, isImplicit).fromSymbols(params.asInstanceOf[List[TermSymbol]], resultType)
117+
make.fromSymbols(params.asInstanceOf[List[TermSymbol]], resultType)
115118
}
116119
if (typeParams.nonEmpty) PolyType.fromParams(typeParams.asInstanceOf[List[TypeSymbol]], monotpe)
117120
else if (valueParamss.isEmpty) ExprType(monotpe)

0 commit comments

Comments
 (0)