aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-11 20:45:41 +0100
committerMartin Odersky <odersky@gmail.com>2017-03-14 12:05:29 +0100
commita3fbe345e17e4ff5d9d02386b73f19ceb69ce524 (patch)
tree4873a790a9a0fcbcfd7a441186a61745c2427e6a /compiler/src/dotty/tools/dotc/core/Types.scala
parent9d0aa36c879f4bde68e01e0ba9decab21d8fce49 (diff)
downloaddotty-a3fbe345e17e4ff5d9d02386b73f19ceb69ce524.tar.gz
dotty-a3fbe345e17e4ff5d9d02386b73f19ceb69ce524.tar.bz2
dotty-a3fbe345e17e4ff5d9d02386b73f19ceb69ce524.zip
Construct dependent method types from symbols
Also: check validity of method types, so that no forward references occur.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala22
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index 460155f92..b59a2503e 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -2478,19 +2478,31 @@ object Types {
case _: ExprType => tp
case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
}
+ def integrate(tp: Type, mt: MethodType) =
+ tp.subst(params, (0 until params.length).toList.map(MethodParam(mt, _)))
def paramInfo(param: Symbol): Type = {
val paramType = translateRepeated(param.info)
if (param.is(Inline)) translateInline(paramType) else paramType
}
- def transformResult(mt: MethodType) =
- resultType.subst(params, (0 until params.length).toList map (MethodParam(mt, _)))
- apply(params map (_.name.asTermName), params map paramInfo)(transformResult _)
+ apply(params.map(_.name.asTermName))(
+ mt => params.map(param => integrate(paramInfo(param), mt)),
+ mt => integrate(resultType, mt))
+ }
+
+ def checkValid(mt: MethodType)(implicit ctx: Context): mt.type = {
+ if (Config.checkMethodTypes)
+ for ((paramType, idx) <- mt.paramTypes.zipWithIndex)
+ paramType.foreachPart {
+ case MethodParam(`mt`, j) => assert(j < idx, mt)
+ case _ =>
+ }
+ mt
}
}
object MethodType extends MethodTypeCompanion {
def apply(paramNames: List[TermName])(paramTypesExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
- unique(new CachedMethodType(paramNames)(paramTypesExp, resultTypeExp))
+ checkValid(unique(new CachedMethodType(paramNames)(paramTypesExp, resultTypeExp)))
private type DependencyStatus = Byte
private final val Unknown: DependencyStatus = 0 // not yet computed
@@ -2508,7 +2520,7 @@ object Types {
object ImplicitMethodType extends MethodTypeCompanion {
def apply(paramNames: List[TermName])(paramTypesExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
- unique(new ImplicitMethodType(paramNames)(paramTypesExp, resultTypeExp))
+ checkValid(unique(new ImplicitMethodType(paramNames)(paramTypesExp, resultTypeExp)))
}
/** A ternary extractor for MethodType */