diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index ee45d93ae532..988d641a0432 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -465,7 +465,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => */ def addTyped(arg: Arg, formal: Type): Type => Type = { addArg(typedArg(arg, formal), formal) - if (methodType.isParamDependent) + if (methodType.isParamDependent && typeOfArg(arg).exists) + // `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg)) else identity } diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 6322105e3e75..8a3fe936c459 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -302,11 +302,13 @@ object ProtoTypes { typer.adapt(targ, formal, locked) } - /** The type of the argument `arg`. - * @pre `arg` has been typed before + /** The type of the argument `arg`, or `NoType` if `arg` has not been typed before + * or if `arg`'s typing produced a type error. */ - def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type = - state.typedArg(arg).tpe + def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type = { + val t = state.typedArg(arg) + if (t == null) NoType else t.tpe + } /** The same proto-type but with all arguments combined in a single tuple */ def tupled: FunProto = state.tupled match { diff --git a/tests/neg/i5311.scala b/tests/neg/i5311.scala new file mode 100644 index 000000000000..b6a0aefe0106 --- /dev/null +++ b/tests/neg/i5311.scala @@ -0,0 +1,13 @@ +object m { + trait Foo { + type T[A] + def bar : (T[Int] => T[Int]) => T[Int => Int] + } + + def baz (implicit S: Foo, f : S.T[Int] => S.T[Int]) : S.T[Int => Int] = + S.bar.apply(f) + + def example(implicit s:Foo) : s.T[Int => Int] = { + baz((x : s.T[Int]) => x) // error + } +} \ No newline at end of file