Skip to content

Commit fd7e267

Browse files
committed
Fix #5311: Survive mistyped arguments of parameter dependent method types
1 parent c63cbd5 commit fd7e267

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
465465
*/
466466
def addTyped(arg: Arg, formal: Type): Type => Type = {
467467
addArg(typedArg(arg, formal), formal)
468-
if (methodType.isParamDependent)
468+
if (methodType.isParamDependent && typeOfArg(arg).exists)
469+
// `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors
469470
safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))
470471
else identity
471472
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ object ProtoTypes {
302302
typer.adapt(targ, formal, locked)
303303
}
304304

305-
/** The type of the argument `arg`.
306-
* @pre `arg` has been typed before
305+
/** The type of the argument `arg`, or `NoType` if `arg` has not been typed before
306+
* or if `arg`'s typing produced a type error.
307307
*/
308-
def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type =
309-
state.typedArg(arg).tpe
308+
def typeOfArg(arg: untpd.Tree)(implicit ctx: Context): Type = {
309+
val t = state.typedArg(arg)
310+
if (t == null) NoType else t.tpe
311+
}
310312

311313
/** The same proto-type but with all arguments combined in a single tuple */
312314
def tupled: FunProto = state.tupled match {

tests/pos/i5311.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object m {
2+
trait Foo {
3+
type T[A]
4+
def bar : (T[Int] => T[Int]) => T[Int => Int]
5+
}
6+
7+
def baz (implicit S: Foo, f : S.T[Int] => S.T[Int]) : S.T[Int => Int] =
8+
S.bar.apply(f)
9+
10+
def example(implicit s:Foo) : s.T[Int => Int] = {
11+
baz((x : s.T[Int]) => x)
12+
}
13+
}

0 commit comments

Comments
 (0)