diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-11 20:45:41 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-03-14 12:05:29 +0100 |
commit | a3fbe345e17e4ff5d9d02386b73f19ceb69ce524 (patch) | |
tree | 4873a790a9a0fcbcfd7a441186a61745c2427e6a /compiler/src/dotty/tools | |
parent | 9d0aa36c879f4bde68e01e0ba9decab21d8fce49 (diff) | |
download | dotty-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')
-rw-r--r-- | compiler/src/dotty/tools/dotc/config/Config.scala | 4 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Types.scala | 22 |
2 files changed, 21 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/config/Config.scala b/compiler/src/dotty/tools/dotc/config/Config.scala index dc56ad8b8..903efd794 100644 --- a/compiler/src/dotty/tools/dotc/config/Config.scala +++ b/compiler/src/dotty/tools/dotc/config/Config.scala @@ -88,6 +88,10 @@ object Config { */ final val checkHKApplications = false + /** If this flag is set, method types are checked for valid parameter references + */ + final val checkMethodTypes = false + /** The recursion depth for showing a summarized string */ final val summarizeDepth = 2 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 */ |