diff options
author | Martin Odersky <odersky@gmail.com> | 2015-02-19 12:18:10 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:14:08 +0100 |
commit | f922a46b09cd65a421f8a61eb1979e651a8e8110 (patch) | |
tree | a6d204483ee0e2b4070a7b51ab87063f2629201c /src/dotty | |
parent | 5b63106448275d6cc4bb6822af33247c2521a63c (diff) | |
download | dotty-f922a46b09cd65a421f8a61eb1979e651a8e8110.tar.gz dotty-f922a46b09cd65a421f8a61eb1979e651a8e8110.tar.bz2 dotty-f922a46b09cd65a421f8a61eb1979e651a8e8110.zip |
Moved part of computation of types of DefDefs from Namer to TypeOps
... so that this can be re-used in the tree unpickler.
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeOps.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 16 |
2 files changed, 19 insertions, 16 deletions
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 3e04eb037..9a9251646 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -10,7 +10,7 @@ import util.SimpleMap import collection.mutable import ast.tpd._ -trait TypeOps { this: Context => +trait TypeOps { this: Context => // TODO: Make standalone object. final def asSeenFrom(tp: Type, pre: Type, cls: Symbol, theMap: AsSeenFromMap): Type = { @@ -402,6 +402,23 @@ trait TypeOps { this: Context => /** Is auto-tupling enabled? */ def canAutoTuple = !featureEnabled(defn.LanguageModuleClass, nme.noAutoTupling) + + def methodType(typeParams: List[Symbol], valueParamss: List[List[Symbol]], resultType: Type, isJava: Boolean = false)(implicit ctx: Context): Type = { + val monotpe = + (valueParamss :\ resultType) { (params, resultType) => + val make = + if (params.nonEmpty && (params.head is Implicit)) ImplicitMethodType + else if (isJava) JavaMethodType + else MethodType + if (isJava) + for (param <- params) + if (param.info.isDirectRef(defn.ObjectClass)) param.info = defn.AnyType + make.fromSymbols(params, resultType) + } + if (typeParams.nonEmpty) PolyType.fromSymbols(typeParams, monotpe) + else if (valueParamss.isEmpty) ExprType(monotpe) + else monotpe + } } object TypeOps { diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 4bf194f5e..9f445c9cd 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -652,21 +652,7 @@ class Namer { typer: Typer => val restpe1 = // try to make anonymous functions non-dependent, so that they can be used in closures if (name == nme.ANON_FUN) avoid(restpe, paramSymss.flatten) else restpe - val monotpe = - (paramSymss :\ restpe1) { (params, restpe) => - val isJava = ddef.mods is JavaDefined - val make = - if (params.nonEmpty && (params.head is Implicit)) ImplicitMethodType - else if(isJava) JavaMethodType - else MethodType - if(isJava) params.foreach { symbol => - if(symbol.info.isDirectRef(defn.ObjectClass)) symbol.info = defn.AnyType - } - make.fromSymbols(params, restpe) - } - if (typeParams.nonEmpty) PolyType.fromSymbols(typeParams, monotpe) - else if (vparamss.isEmpty) ExprType(monotpe) - else monotpe + ctx.methodType(tparams map symbolOfTree, paramSymss, restpe1, isJava = ddef.mods is JavaDefined) } if (isConstructor) { // set result type tree to unit, but take the current class as result type of the symbol |