From a3fbe345e17e4ff5d9d02386b73f19ceb69ce524 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 11 Mar 2017 20:45:41 +0100 Subject: Construct dependent method types from symbols Also: check validity of method types, so that no forward references occur. --- compiler/src/dotty/tools/dotc/core/Types.scala | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/core/Types.scala') 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 */ -- cgit v1.2.3