aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-10 19:38:39 +0100
committerMartin Odersky <odersky@gmail.com>2017-03-14 12:05:29 +0100
commit9d0aa36c879f4bde68e01e0ba9decab21d8fce49 (patch)
treeb8f4e99a9d32f3ba657c9e707d45b91923fdeed9 /compiler/src/dotty/tools/dotc/typer
parent3a93b3ee128bae804044b25aa7354ce32e074678 (diff)
downloaddotty-9d0aa36c879f4bde68e01e0ba9decab21d8fce49.tar.gz
dotty-9d0aa36c879f4bde68e01e0ba9decab21d8fce49.tar.bz2
dotty-9d0aa36c879f4bde68e01e0ba9decab21d8fce49.zip
Construct MethodTypes from parameter closure
To allow for dependencies between method type parameters, construct MethodTypes from a closure that maps the currently constructed MethodType to its parameter types.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Applications.scala3
-rw-r--r--compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/typer/ReTyper.scala4
-rw-r--r--compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala6
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala8
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Variances.scala4
6 files changed, 15 insertions, 14 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala
index a65ef00cc..b459e2745 100644
--- a/compiler/src/dotty/tools/dotc/typer/Applications.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala
@@ -1263,7 +1263,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
def sizeFits(alt: TermRef, tp: Type): Boolean = tp match {
case tp: PolyType => sizeFits(alt, tp.resultType)
- case MethodType(_, ptypes) =>
+ case tp: MethodType =>
+ val ptypes = tp.paramTypes
val numParams = ptypes.length
def isVarArgs = ptypes.nonEmpty && ptypes.last.isRepeatedParam
def hasDefault = alt.symbol.hasDefaultParams
diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
index e7e7ece78..57c1808c9 100644
--- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
+++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
@@ -59,8 +59,8 @@ object EtaExpansion {
*/
def liftArgs(defs: mutable.ListBuffer[Tree], methRef: Type, args: List[Tree])(implicit ctx: Context) =
methRef.widen match {
- case MethodType(paramNames, paramTypes) =>
- (args, paramNames, paramTypes).zipped map { (arg, name, tp) =>
+ case mt: MethodType =>
+ (args, mt.paramNames, mt.paramTypes).zipped map { (arg, name, tp) =>
if (tp.isInstanceOf[ExprType]) arg
else liftArg(defs, arg, if (name contains '$') "" else name.toString + "$")
}
diff --git a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala
index 3252ead47..6080c6644 100644
--- a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala
+++ b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala
@@ -85,8 +85,8 @@ class ReTyper extends Typer {
override def encodeName(tree: untpd.NameTree)(implicit ctx: Context) = tree
override def handleUnexpectedFunType(tree: untpd.Apply, fun: Tree)(implicit ctx: Context): Tree = fun.tpe match {
- case mt @ MethodType(_, formals) =>
- val args: List[Tree] = tree.args.zipWithConserve(formals)(typedExpr(_, _)).asInstanceOf[List[Tree]]
+ case mt: MethodType =>
+ val args: List[Tree] = tree.args.zipWithConserve(mt.paramTypes)(typedExpr(_, _)).asInstanceOf[List[Tree]]
assignType(untpd.cpy.Apply(tree)(fun, args), fun, args)
case _ =>
super.handleUnexpectedFunType(tree, fun)
diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
index 6bf8dcbbc..6e774e38e 100644
--- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
+++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
@@ -315,10 +315,10 @@ trait TypeAssigner {
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = {
val ownType = fn.tpe.widen match {
- case fntpe @ MethodType(_, ptypes) =>
- if (sameLength(ptypes, args) || ctx.phase.prev.relaxedTyping) fntpe.instantiate(args.tpes)
+ case fntpe: MethodType =>
+ if (sameLength(fntpe.paramTypes, args) || ctx.phase.prev.relaxedTyping) fntpe.instantiate(args.tpes)
else
- errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${ptypes.length}, found: ${args.length}", tree.pos)
+ errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramTypes.length}, found: ${args.length}", tree.pos)
case t =>
errorType(i"${err.exprStr(fn)} does not take parameters", tree.pos)
}
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index fd0c7c73d..4bf87dd81 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -672,8 +672,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
// this can type the greatest set of admissible closures.
(pt.dealias.argTypesLo.init, pt.dealias.argTypesHi.last)
case SAMType(meth) =>
- val mt @ MethodType(_, paramTypes) = meth.info
- (paramTypes, mt.resultType)
+ val MethodTpe(_, formals, restpe) = meth.info
+ (formals, restpe)
case _ =>
(List.range(0, defaultArity) map alwaysWildcardType, WildcardType)
}
@@ -1287,10 +1287,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def maybeCall(ref: Tree, psym: Symbol, cinfo: Type): Tree = cinfo match {
case cinfo: PolyType =>
maybeCall(ref, psym, cinfo.resultType)
- case cinfo @ MethodType(Nil, _) if cinfo.resultType.isInstanceOf[ImplicitMethodType] =>
+ case cinfo @ MethodType(Nil) if cinfo.resultType.isInstanceOf[ImplicitMethodType] =>
val icall = New(ref).select(nme.CONSTRUCTOR).appliedToNone
typedExpr(untpd.TypedSplice(icall))(superCtx)
- case cinfo @ MethodType(Nil, _) if !cinfo.resultType.isInstanceOf[MethodType] =>
+ case cinfo @ MethodType(Nil) if !cinfo.resultType.isInstanceOf[MethodType] =>
ref
case cinfo: MethodType =>
if (!ctx.erasedTypes) { // after constructors arguments are passed in super call.
diff --git a/compiler/src/dotty/tools/dotc/typer/Variances.scala b/compiler/src/dotty/tools/dotc/typer/Variances.scala
index 92bd9fd74..5a1745930 100644
--- a/compiler/src/dotty/tools/dotc/typer/Variances.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Variances.scala
@@ -79,8 +79,8 @@ object Variances {
varianceInType(parent)(tparam) & varianceInType(rinfo)(tparam)
case tp: RecType =>
varianceInType(tp.parent)(tparam)
- case tp @ MethodType(_, paramTypes) =>
- flip(varianceInTypes(paramTypes)(tparam)) & varianceInType(tp.resultType)(tparam)
+ case tp: MethodType =>
+ flip(varianceInTypes(tp.paramTypes)(tparam)) & varianceInType(tp.resultType)(tparam)
case ExprType(restpe) =>
varianceInType(restpe)(tparam)
case tp @ HKApply(tycon, args) =>