Skip to content

Commit 934da77

Browse files
authored
Merge pull request #2079 from dotty-staging/depmeth2
Allow inter-parameter dependencies
2 parents 1aad0a1 + 3c22580 commit 934da77

33 files changed

+242
-142
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CollectEntryPoints extends MiniPhaseTransform {
4949
object CollectEntryPoints{
5050
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context) = {
5151
(sym.name == nme.main) && (sym.info match {
52-
case r@MethodType(_, List(defn.ArrayOf(t))) =>
52+
case r@MethodTpe(_, List(defn.ArrayOf(t)), _) =>
5353
(t.widenDealias =:= defn.StringType) && (
5454
r.resultType.widenDealias =:= defn.UnitType)
5555
case _ => false
@@ -81,9 +81,8 @@ object CollectEntryPoints{
8181
val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil
8282
val hasApproximate = possibles exists { m =>
8383
m.info match {
84-
case MethodType(_, p :: Nil) =>
85-
p.typeSymbol == defn.ArrayClass
86-
case _ => false
84+
case MethodTpe(_, p :: Nil, _) => p.typeSymbol == defn.ArrayClass
85+
case _ => false
8786
}
8887
}
8988
// At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
@@ -108,8 +107,8 @@ object CollectEntryPoints{
108107
toDenot(m.symbol).info match {
109108
case t: PolyType =>
110109
fail("main methods cannot be generic.")
111-
case t@MethodType(paramNames, paramTypes) =>
112-
if (t.resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
110+
case MethodTpe(paramNames, paramTypes, resultType) =>
111+
if (resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
113112
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.pos)
114113
else
115114
isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
531531
tree match {
532532
case Apply(fun, args) =>
533533
fun.tpe.widen match {
534-
case MethodType(names, _) =>
534+
case MethodType(names) =>
535535
names zip args
536536
}
537537
}

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
185185
}
186186

187187
def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match {
188-
case tp @ MethodType(paramNames, paramTypes) =>
188+
case tp: MethodType =>
189189
def valueParam(name: TermName, info: Type): TermSymbol = {
190190
val maybeImplicit = if (tp.isInstanceOf[ImplicitMethodType]) Implicit else EmptyFlags
191191
ctx.newSymbol(sym, name, TermParam | maybeImplicit, info)
192192
}
193-
val params = (paramNames, paramTypes).zipped.map(valueParam)
193+
val params = (tp.paramNames, tp.paramTypes).zipped.map(valueParam)
194194
val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef)))
195195
(params :: paramss, rtp)
196196
case tp => (Nil, tp.widenExpr)

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ object Config {
8888
*/
8989
final val checkHKApplications = false
9090

91+
/** If this flag is set, method types are checked for valid parameter references
92+
*/
93+
final val checkMethodTypes = false
94+
9195
/** The recursion depth for showing a summarized string */
9296
final val summarizeDepth = 2
9397

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JavaPlatform extends Platform {
2323
// The given symbol is a method with the right name and signature to be a runnable java program.
2424
def isJavaMainMethod(sym: SymDenotation)(implicit ctx: Context) =
2525
(sym.name == nme.main) && (sym.info match {
26-
case t@MethodType(_, defn.ArrayOf(el) :: Nil) => el =:= defn.StringType && (t.resultType isRef defn.UnitClass)
26+
case MethodTpe(_, defn.ArrayOf(el) :: Nil, restpe) => el =:= defn.StringType && (restpe isRef defn.UnitClass)
2727
case _ => false
2828
})
2929

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ object Denotations {
308308
case tp2: TypeBounds if tp2 contains tp1 => tp1
309309
case _ => mergeConflict(tp1, tp2)
310310
}
311-
case tp1 @ MethodType(names1, formals1) if isTerm =>
311+
case tp1: MethodType if isTerm =>
312312
tp2 match {
313-
case tp2 @ MethodType(names2, formals2) if ctx.typeComparer.matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
313+
case tp2: MethodType if ctx.typeComparer.matchingParams(tp1.paramTypes, tp2.paramTypes, tp1.isJava, tp2.isJava) &&
314314
tp1.isImplicit == tp2.isImplicit =>
315315
tp1.derivedMethodType(
316-
mergeNames(names1, names2, nme.syntheticParamName),
317-
formals1,
316+
mergeNames(tp1.paramNames, tp2.paramNames, nme.syntheticParamName),
317+
tp1.paramTypes,
318318
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
319319
case _ =>
320320
mergeConflict(tp1, tp2)
@@ -471,14 +471,14 @@ object Denotations {
471471
case tp2: TypeBounds if tp2 contains tp1 => tp2
472472
case _ => mergeConflict(tp1, tp2)
473473
}
474-
case tp1 @ MethodType(names1, formals1) =>
474+
case tp1: MethodType =>
475475
tp2 match {
476-
case tp2 @ MethodType(names2, formals2)
477-
if ctx.typeComparer.matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
476+
case tp2: MethodType
477+
if ctx.typeComparer.matchingParams(tp1.paramTypes, tp2.paramTypes, tp1.isJava, tp2.isJava) &&
478478
tp1.isImplicit == tp2.isImplicit =>
479479
tp1.derivedMethodType(
480-
mergeNames(names1, names2, nme.syntheticParamName),
481-
formals1, tp1.resultType | tp2.resultType.subst(tp2, tp1))
480+
mergeNames(tp1.paramNames, tp2.paramNames, nme.syntheticParamName),
481+
tp1.paramTypes, tp1.resultType | tp2.resultType.subst(tp2, tp1))
482482
case _ =>
483483
mergeConflict(tp1, tp2)
484484
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ trait Symbols { this: Context =>
252252

253253
/** Create a class constructor symbol for given class `cls`. */
254254
def newConstructor(cls: ClassSymbol, flags: FlagSet, paramNames: List[TermName], paramTypes: List[Type], privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
255-
newSymbol(cls, nme.CONSTRUCTOR, flags | Method, MethodType(paramNames, paramTypes)(_ => cls.typeRef), privateWithin, coord)
255+
newSymbol(cls, nme.CONSTRUCTOR, flags | Method, MethodType(paramNames, paramTypes, cls.typeRef), privateWithin, coord)
256256

257257
/** Create an empty default constructor symbol for given class `cls`. */
258258
def newDefaultConstructor(cls: ClassSymbol) =

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
484484
case _ =>
485485
}
486486
either(isSubType(tp1, tp21), isSubType(tp1, tp22)) || fourthTry(tp1, tp2)
487-
case tp2 @ MethodType(_, formals2) =>
487+
case tp2: MethodType =>
488488
def compareMethod = tp1 match {
489-
case tp1 @ MethodType(_, formals1) =>
489+
case tp1: MethodType =>
490490
(tp1.signature consistentParams tp2.signature) &&
491-
matchingParams(formals1, formals2, tp1.isJava, tp2.isJava) &&
491+
matchingParams(tp1.paramTypes, tp2.paramTypes, tp1.isJava, tp2.isJava) &&
492492
(tp1.isImplicit == tp2.isImplicit) &&
493493
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
494494
case _ =>
@@ -503,7 +503,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
503503
// as members of the same type. And it seems most logical to take
504504
// ()T <:< => T, since everything one can do with a => T one can
505505
// also do with a ()T by automatic () insertion.
506-
case tp1 @ MethodType(Nil, _) => isSubType(tp1.resultType, restpe2)
506+
case tp1 @ MethodType(Nil) => isSubType(tp1.resultType, restpe2)
507507
case _ => isSubType(tp1.widenExpr, restpe2)
508508
}
509509
compareExpr

0 commit comments

Comments
 (0)