diff options
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 2aa7036b4..ec6fb1770 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -91,8 +91,8 @@ trait TypeAssigner { else parent } - val refinableDecls = info.decls.filterNot( - sym => sym.is(TypeParamAccessor | Private) || sym.isConstructor) + val refinableDecls = info.decls.filter( + sym => !(sym.is(TypeParamAccessor | Private) || sym.isConstructor)) val fullType = (parentType /: refinableDecls)(addRefinement) mapOver(fullType) case TypeBounds(lo, hi) if variance > 0 => @@ -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 safeSubstParam(tp: Type, pref: ParamRef, argType: Type)(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 safeSubstParams(tp: Type, params: List[ParamRef], args: List[Tree]): Type = params match { + case param :: params1 => + val tp1 = safeSubstParam(tp, param, args.head.tpe) + safeSubstParams(tp1, params1, args.tail) + case Nil => + tp + } + if (sameLength(fntpe.paramInfos, args) || ctx.phase.prev.relaxedTyping) + if (fntpe.isDependent) safeSubstParams(fntpe.resultType, fntpe.paramRefs, args) + 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 => |