From 6195995c9f7784ec5d77956e162b1908d24c2ec7 Mon Sep 17 00:00:00 2001 From: Yoonjae Jeon Date: Wed, 7 May 2025 22:13:17 +0900 Subject: [PATCH 1/2] patvar: adjust caret in error message --- .../dotty/tools/dotc/parsing/Parsers.scala | 2 +- tests/neg/i15784.check | 24 +++++++++---------- tests/neg/t5702-neg-bad-and-wild.check | 7 ------ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 9d53dfa3585d..628fa50211c3 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2971,7 +2971,7 @@ object Parsers { | * variable pattern, e.g. `case x: String =>` | * number literal pattern, e.g. `case 10.5: Double =>` |are no longer supported. Remove the type ascription or move it to a separate variable pattern.""", - in.sourcePos(), + p.sourcePos, warnFrom = `3.3`, errorFrom = future ) diff --git a/tests/neg/i15784.check b/tests/neg/i15784.check index 7d015689950d..d8c9c193c7dc 100644 --- a/tests/neg/i15784.check +++ b/tests/neg/i15784.check @@ -10,17 +10,17 @@ | Not found: A | | longer explanation available when compiling with `-explain` --- Warning: tests/neg/i15784.scala:7:8 --------------------------------------------------------------------------------- +-- Warning: tests/neg/i15784.scala:7:7 --------------------------------------------------------------------------------- 7 | case X: Int => X // warn - | ^ - | Type ascriptions after patterns other than: - | * variable pattern, e.g. `case x: String =>` - | * number literal pattern, e.g. `case 10.5: Double =>` - | are no longer supported. Remove the type ascription or move it to a separate variable pattern. --- Warning: tests/neg/i15784.scala:10:12 ------------------------------------------------------------------------------- + | ^ + | Type ascriptions after patterns other than: + | * variable pattern, e.g. `case x: String =>` + | * number literal pattern, e.g. `case 10.5: Double =>` + | are no longer supported. Remove the type ascription or move it to a separate variable pattern. +-- Warning: tests/neg/i15784.scala:10:7 -------------------------------------------------------------------------------- 10 | case `Int`: Int => `Int` // warn - | ^ - | Type ascriptions after patterns other than: - | * variable pattern, e.g. `case x: String =>` - | * number literal pattern, e.g. `case 10.5: Double =>` - | are no longer supported. Remove the type ascription or move it to a separate variable pattern. + | ^^^^^ + | Type ascriptions after patterns other than: + | * variable pattern, e.g. `case x: String =>` + | * number literal pattern, e.g. `case 10.5: Double =>` + | are no longer supported. Remove the type ascription or move it to a separate variable pattern. diff --git a/tests/neg/t5702-neg-bad-and-wild.check b/tests/neg/t5702-neg-bad-and-wild.check index 261b2a9e44d1..da6d551bd3b3 100644 --- a/tests/neg/t5702-neg-bad-and-wild.check +++ b/tests/neg/t5702-neg-bad-and-wild.check @@ -46,13 +46,6 @@ | no pattern match extractor named * was found | | longer explanation available when compiling with `-explain` --- Warning: tests/neg/t5702-neg-bad-and-wild.scala:13:22 --------------------------------------------------------------- -13 | case List(1, _*3:) => // error // error - | ^ - | Type ascriptions after patterns other than: - | * variable pattern, e.g. `case x: String =>` - | * number literal pattern, e.g. `case 10.5: Double =>` - | are no longer supported. Remove the type ascription or move it to a separate variable pattern. -- Warning: tests/neg/t5702-neg-bad-and-wild.scala:22:20 --------------------------------------------------------------- 22 | val K(x @ _*) = k | ^ From 4e1b2be02378f96f0e7fa31e16b6d535cf0bcab2 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 12 May 2025 12:19:13 +0200 Subject: [PATCH 2/2] patvar: adjust caret in error message [Cherry-picked c49ff7141a0102860b2d4ef24000dfbf7f0d6e87][modified]