Skip to content

Fix #5311: Survive mistyped arguments of parameter dependent method types #5312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions tests/neg/i5311.scala
Original file line number Diff line number Diff line change
@@ -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
}
}