Skip to content

Fix #13223: Disalow ? in match types pats/bodies #13241

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 3 commits 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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ object Parsers {

def typeDependingOn(location: Location): Tree =
if location.inParens then typ()
else if location.inPattern then refinedType()
else if location.inPattern then rejectWildcardType(refinedType())
else infixType()

/* ----------- EXPRESSIONS ------------------------------------------------ */
Expand Down Expand Up @@ -2609,10 +2609,10 @@ object Parsers {
def typeCaseClause(): CaseDef = atSpan(in.offset) {
val pat = inSepRegion(InCase) {
accept(CASE)
infixType()
rejectWildcardType(infixType())
}
CaseDef(pat, EmptyTree, atSpan(accept(ARROW)) {
val t = typ()
val t = rejectWildcardType(typ())
newLinesOptWhenFollowedBy(CASE)
t
})
Expand Down
15 changes: 15 additions & 0 deletions tests/neg/12261.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type M0[X] = X match {
case ? => String // error: Unbound wildcard type
}

type M1[X] = X match {
case Any => _ // error: Unbound wildcard type
}

type M2[X] = X match {
case Any => ? // error: Unbound wildcard type
}

val a = "" match { case _: _ => () } // error: Unbound wildcard type

val b = try { } catch { case _: _ => () } // error: Unbound wildcard type
2 changes: 1 addition & 1 deletion tests/pos/9239.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ object ABug:
N match
case Zero => One
case One => One
case ? => ![--[N]] × (N)
case _ => ![--[N]] × (N)
case ? :: ? => ![--[N]] × (N)