Skip to content

Commit 48bd96d

Browse files
committed
Construct dependent method types from symbols
Also: check validity of method types, so that no forward references occur.
1 parent e99a26d commit 48bd96d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ object Config {
8888
*/
8989
final val checkHKApplications = false
9090

91+
/** If this flag is set, method types are checked for valid parameter references
92+
*/
93+
final val checkMethodTypes = false
94+
9195
/** The recursion depth for showing a summarized string */
9296
final val summarizeDepth = 2
9397

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,19 +2478,31 @@ object Types {
24782478
case _: ExprType => tp
24792479
case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
24802480
}
2481+
def integrate(tp: Type, mt: MethodType) =
2482+
tp.subst(params, (0 until params.length).toList.map(MethodParam(mt, _)))
24812483
def paramInfo(param: Symbol): Type = {
24822484
val paramType = translateRepeated(param.info)
24832485
if (param.is(Inline)) translateInline(paramType) else paramType
24842486
}
2485-
def transformResult(mt: MethodType) =
2486-
resultType.subst(params, (0 until params.length).toList map (MethodParam(mt, _)))
2487-
apply(params map (_.name.asTermName), params map paramInfo)(transformResult _)
2487+
apply(params.map(_.name.asTermName))(
2488+
mt => params.map(param => integrate(paramInfo(param), mt)),
2489+
mt => integrate(resultType, mt))
2490+
}
2491+
2492+
def checkValid(mt: MethodType)(implicit ctx: Context): mt.type = {
2493+
if (Config.checkMethodTypes)
2494+
for ((paramType, idx) <- mt.paramTypes.zipWithIndex)
2495+
paramType.foreachPart {
2496+
case MethodParam(`mt`, j) => assert(j < idx, mt)
2497+
case _ =>
2498+
}
2499+
mt
24882500
}
24892501
}
24902502

24912503
object MethodType extends MethodTypeCompanion {
24922504
def apply(paramNames: List[TermName])(paramTypesExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
2493-
unique(new CachedMethodType(paramNames)(paramTypesExp, resultTypeExp))
2505+
checkValid(unique(new CachedMethodType(paramNames)(paramTypesExp, resultTypeExp)))
24942506

24952507
private type DependencyStatus = Byte
24962508
private final val Unknown: DependencyStatus = 0 // not yet computed
@@ -2508,7 +2520,7 @@ object Types {
25082520

25092521
object ImplicitMethodType extends MethodTypeCompanion {
25102522
def apply(paramNames: List[TermName])(paramTypesExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
2511-
unique(new ImplicitMethodType(paramNames)(paramTypesExp, resultTypeExp))
2523+
checkValid(unique(new ImplicitMethodType(paramNames)(paramTypesExp, resultTypeExp)))
25122524
}
25132525

25142526
/** A ternary extractor for MethodType */

0 commit comments

Comments
 (0)