Skip to content

Commit 5afc086

Browse files
committed
Do relaxedTyping everywhere
If all phases run at group end, any phase that adds or removes method parameters makes all phases run before it in the same group have the wrong number of parameters when type assigning an Apply or TypeApply. Previously this was allowed only if relaxedTyping was true. Now it is allowed everywhere. We should still be able to catch any errors in the transformer logic using Ycheck. With this change, LinkScala2Impls can now be run at group end.
1 parent cca541f commit 5afc086

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,6 @@ object Phases {
298298
*/
299299
def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = ()
300300

301-
/** If set, allow missing or superfluous arguments in applications
302-
* and type applications.
303-
*/
304-
def relaxedTyping: Boolean = false
305-
306301
/** Is this phase the standard typerphase? True for FrontEnd, but
307302
* not for other first phases (such as FromTasty). The predicate
308303
* is tested in some places that perform checks and corrections. It's

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
6464
val phaseName: String = "lambdaLift"
6565
val treeTransform = new LambdaLifter
6666

67-
override def relaxedTyping = true
68-
6967
override def runsAfterGroupsOf: Set[Class[_ <: Phase]] = Set(classOf[Constructors], classOf[HoistSuperArgs])
7068
// Constructors has to happen before LambdaLift because the lambda lift logic
7169
// becomes simpler if it can assume that parameter accessors have already been

compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisTran
4848
class Transform extends TreeTransform {
4949
def phase = thisTransform
5050

51-
//override def treeTransformPhase(implicit ctx: Context, info: TransformerInfo) =
52-
// groupEndPhase
51+
override def treeTransformPhase(implicit ctx: Context, info: TransformerInfo) =
52+
groupEndPhase
5353

5454
/** Copy definitions from implementation class to trait itself */
5555
private def augmentScala_2_12_Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,23 @@ trait TypeAssigner {
334334
else tp.substParam(pref, SkolemType(argType.widen))
335335
}
336336

337+
/** Substitute types of all arguments `args` for corresponding `params` in `tp`.
338+
* The number of parameters `params` may exceed the number of arguments.
339+
* In this case, only the common prefix is substituted.
340+
*/
341+
def safeSubstParams(tp: Type, params: List[ParamRef], argTypes: List[Type])(implicit ctx: Context): Type = argTypes match {
342+
case argType :: argTypes1 =>
343+
val tp1 = safeSubstParam(tp, params.head, argType)
344+
safeSubstParams(tp1, params.tail, argTypes1)
345+
case Nil =>
346+
tp
347+
}
348+
337349
def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = {
338350
val ownType = fn.tpe.widen match {
339351
case fntpe: MethodType =>
340-
def safeSubstParams(tp: Type, params: List[ParamRef], args: List[Tree]): Type = params match {
341-
case param :: params1 =>
342-
val tp1 = safeSubstParam(tp, param, args.head.tpe)
343-
safeSubstParams(tp1, params1, args.tail)
344-
case Nil =>
345-
tp
346-
}
347-
if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping)
348-
if (fntpe.isDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args)
349-
else fntpe.resultType
350-
else
351-
errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos)
352+
if (fntpe.isDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args.tpes)
353+
else fntpe.resultType
352354
case t =>
353355
errorType(err.takesNoParamsStr(fn, ""), tree.pos)
354356
}
@@ -404,7 +406,7 @@ trait TypeAssigner {
404406
}
405407
else {
406408
val argTypes = preCheckKinds(args, pt.paramInfos).tpes
407-
if (sameLength(argTypes, paramNames) || ctx.phase.prev.relaxedTyping) pt.instantiate(argTypes)
409+
if (sameLength(argTypes, paramNames)) pt.instantiate(argTypes)
408410
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
409411
}
410412
case _ =>

0 commit comments

Comments
 (0)