Skip to content

Fix #1716: avoid crash in type checking f[_] #1858

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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ trait TypeAssigner {
}
else {
val argTypes = args.tpes
if (sameLength(argTypes, paramNames) || ctx.phase.prev.relaxedTyping) pt.instantiate(argTypes)
if (sameLength(argTypes, paramNames) || ctx.phase.prev.relaxedTyping) {
val index = argTypes.indexWhere(!_.isInstanceOf[TermType])
if (index != -1)
errorType(i"Incorrect type parameter `${args(index)}` for ${err.exprStr(fn)}", args(index).pos)
else pt.instantiate(argTypes)
}
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
}
case _ =>
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i1716.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Fail {
def f(m: Option[Int]): Unit = {
m match {
case x @ Some[_] => // error
case _ =>
}
}
}
5 changes: 5 additions & 0 deletions tests/neg/i1716b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Fail {
def f: Unit = {
Some[_] // error
}
}