Skip to content
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

Do not warn on underscore wildcard type in pattern #19249

Merged
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
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,12 @@ object Parsers {
finally inEnum = saved
}

private var inTypeMatchPattern = false
private def withinTypeMatchPattern[T](body: => T): T = {
val saved = inTypeMatchPattern
inTypeMatchPattern = true
private var inMatchPattern = false
private def withinMatchPattern[T](body: => T): T = {
val saved = inMatchPattern
inMatchPattern = true
try body
finally inTypeMatchPattern = saved
finally inMatchPattern = saved
}

private var staged = StageKind.None
Expand Down Expand Up @@ -1881,7 +1881,7 @@ object Parsers {
val start = in.skipToken()
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
else
if !inTypeMatchPattern then
if !inMatchPattern then
report.errorOrMigrationWarning(
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
in.sourcePos(),
Expand Down Expand Up @@ -2896,7 +2896,7 @@ object Parsers {
def caseClause(exprOnly: Boolean = false): CaseDef = atSpan(in.offset) {
val (pat, grd) = inSepRegion(InCase) {
accept(CASE)
(pattern(), guard())
(withinMatchPattern(pattern()), guard())
}
CaseDef(pat, grd, atSpan(accept(ARROW)) {
if exprOnly then
Expand All @@ -2920,7 +2920,7 @@ object Parsers {
val start = in.skipToken()
Ident(tpnme.WILDCARD).withSpan(Span(start, in.lastOffset, start))
case _ =>
withinTypeMatchPattern(rejectWildcardType(infixType()))
withinMatchPattern(rejectWildcardType(infixType()))
}
}
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {
Expand Down
5 changes: 0 additions & 5 deletions tests/neg/wildcard-type-syntax-3.4.check

This file was deleted.

8 changes: 0 additions & 8 deletions tests/neg/wildcard-type-syntax-3.4.scala

This file was deleted.

8 changes: 0 additions & 8 deletions tests/neg/wildcard-type-syntax-future-migration.scala

This file was deleted.

6 changes: 0 additions & 6 deletions tests/neg/wildcard-type-syntax-future.scala

This file was deleted.

2 changes: 0 additions & 2 deletions tests/pos/wildcard-type-syntax.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//> using options -Werror

import scala.language.`3.3`

def test =
Seq() match
case _: List[_] =>
Expand Down
8 changes: 2 additions & 6 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Text => empty
Language => Scala
Symbols => 61 entries
Occurrences => 143 entries
Diagnostics => 4 entries
Diagnostics => 3 entries
Synthetics => 3 entries

Symbols:
Expand Down Expand Up @@ -278,8 +278,6 @@ Diagnostics:
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[21:15..21:15): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[39:20..39:20): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[40:12..40:15): [warning] unused local definition

Synthetics:
Expand Down Expand Up @@ -395,7 +393,7 @@ Text => empty
Language => Scala
Symbols => 23 entries
Occurrences => 50 entries
Diagnostics => 4 entries
Diagnostics => 3 entries
Synthetics => 2 entries

Symbols:
Expand Down Expand Up @@ -480,8 +478,6 @@ Diagnostics:
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[9:22..9:22): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[11:29..11:29): [warning] `_` is deprecated for wildcard arguments of types: use `?` instead
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
[14:8..14:9): [warning] unused local definition

Synthetics:
Expand Down
Loading