diff options
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 2aa7036b4..d04b16451 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -315,10 +315,28 @@ trait TypeAssigner { } } + /** Substitute argument type `argType` for parameter `pref` in type `tp`, + * skolemizing the argument type if it is not stable and `pref` occurs in `tp`. + */ + def substArgForParam(tp: Type, argType: Type, pref: ParamRef)(implicit ctx: Context) = { + val tp1 = tp.substParam(pref, argType) + if ((tp1 eq tp) || argType.isStable) tp1 + else tp.substParam(pref, SkolemType(argType.widen)) + } + def assignType(tree: untpd.Apply, fn: Tree, args: List[Tree])(implicit ctx: Context) = { val ownType = fn.tpe.widen match { case fntpe: MethodType => - if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) fntpe.instantiate(args.tpes) + def substArgsForParams(tp: Type, args: List[Tree], params: List[ParamRef]): Type = params match { + case param :: params1 => + val tp1 = substArgForParam(tp, args.head.tpe, param) + substArgsForParams(tp1, args.tail, params1) + case Nil => + tp + } + if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) + if (fntpe.isDependent) substArgsForParams(fntpe.resultType, args, fntpe.paramRefs) + else fntpe.resultType else errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos) case t => |