From 35975432852a7b67ca3dc6d34feaaf3797549ee1 Mon Sep 17 00:00:00 2001 From: SDSR Date: Tue, 26 Oct 2021 19:07:49 +0200 Subject: [PATCH] solves dotc assertion error on (non-sensical?) parameter type. #13769 --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 3 +++ tests/neg/i13769.check | 10 ++++++++++ tests/neg/i13769.scala | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 tests/neg/i13769.check create mode 100644 tests/neg/i13769.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 44e7145d2ee1..aff7218e662b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -442,6 +442,9 @@ object Parsers { def convertToParam(tree: Tree, mods: Modifiers, expected: String = "formal parameter"): ValDef = tree match { case id @ Ident(name) => makeParameter(name.asTermName, TypeTree(), mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) + case Typed(_, tpt: TypeBoundsTree) => + syntaxError(s"not a legal $expected", tree.span) + makeParameter(nme.ERROR, tree, mods) case Typed(id @ Ident(name), tpt) => makeParameter(name.asTermName, tpt, mods, isBackquoted = isBackquoted(id)).withSpan(tree.span) case Typed(Splice(Ident(name)), tpt) => diff --git a/tests/neg/i13769.check b/tests/neg/i13769.check new file mode 100644 index 000000000000..7785fbf4d198 --- /dev/null +++ b/tests/neg/i13769.check @@ -0,0 +1,10 @@ +-- Error: tests/neg/i13769.scala:2:18 ---------------------------------------------------------------------------------- +2 |val te = tup.map((x: _ <: Int) => List(x)) // error // error + | ^^^^^^^^^^^ + | not a legal formal parameter +-- [E006] Not Found Error: tests/neg/i13769.scala:2:39 ----------------------------------------------------------------- +2 |val te = tup.map((x: _ <: Int) => List(x)) // error // error + | ^ + | Not found: x + +longer explanation available when compiling with `-explain` \ No newline at end of file diff --git a/tests/neg/i13769.scala b/tests/neg/i13769.scala new file mode 100644 index 000000000000..67575e821334 --- /dev/null +++ b/tests/neg/i13769.scala @@ -0,0 +1,2 @@ +val tup = (1, "s") +val te = tup.map((x: _ <: Int) => List(x)) // error // error