From 052008313d5f72ffbbfe12fef6baf759f80be0eb Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Sat, 24 Dec 2016 23:26:02 +0100 Subject: [PATCH] Fix #1716: avoid crash in type checking f[_] --- compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 7 ++++++- tests/neg/i1716.scala | 8 ++++++++ tests/neg/i1716b.scala | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i1716.scala create mode 100644 tests/neg/i1716b.scala diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 4a97648f5825..ca219d8b3af1 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -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 _ => diff --git a/tests/neg/i1716.scala b/tests/neg/i1716.scala new file mode 100644 index 000000000000..61b573512f1a --- /dev/null +++ b/tests/neg/i1716.scala @@ -0,0 +1,8 @@ +object Fail { + def f(m: Option[Int]): Unit = { + m match { + case x @ Some[_] => // error + case _ => + } + } +} \ No newline at end of file diff --git a/tests/neg/i1716b.scala b/tests/neg/i1716b.scala new file mode 100644 index 000000000000..b125a9328fbd --- /dev/null +++ b/tests/neg/i1716b.scala @@ -0,0 +1,5 @@ +object Fail { + def f: Unit = { + Some[_] // error + } +} \ No newline at end of file