From 56adc54824c4457b9a3fdadbe065ba5a8511c0ef Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Tue, 3 Aug 2021 11:41:21 +0200 Subject: [PATCH 1/3] Fix #13223: Disalow ? in match types pats/bodies --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 ++-- tests/neg/12261.scala | 11 +++++++++++ tests/pos/9239.scala | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/neg/12261.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 399eabfff0f1..e9224d3ae9cf 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 }) diff --git a/tests/neg/12261.scala b/tests/neg/12261.scala new file mode 100644 index 000000000000..9848e68fa160 --- /dev/null +++ b/tests/neg/12261.scala @@ -0,0 +1,11 @@ +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 +} diff --git a/tests/pos/9239.scala b/tests/pos/9239.scala index 8f3ddfbd1ced..c9c0ec268218 100644 --- a/tests/pos/9239.scala +++ b/tests/pos/9239.scala @@ -24,5 +24,5 @@ object ABug: N match case Zero => One case One => One - case ? => ![--[N]] × (N) + case _ => ![--[N]] × (N) case ? :: ? => ![--[N]] × (N) From ace8187272a02ab8635dbf0085beb662b102990c Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Sat, 31 Jul 2021 08:49:11 +0200 Subject: [PATCH 2/3] Also disalow unbound wildcard type in pattern expr --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- tests/neg/12261.scala | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index e9224d3ae9cf..6d152dc116d8 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 ------------------------------------------------ */ diff --git a/tests/neg/12261.scala b/tests/neg/12261.scala index 9848e68fa160..70120671a05b 100644 --- a/tests/neg/12261.scala +++ b/tests/neg/12261.scala @@ -9,3 +9,7 @@ type M1[X] = X match { 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 From dca7f3c10f285ffde0e59725895a1ee07403bc5d Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Tue, 3 Aug 2021 11:46:09 +0200 Subject: [PATCH 3/3] Update community build (scodec) --- community-build/community-projects/scodec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scodec b/community-build/community-projects/scodec index 18047cac1feb..d59c0440b078 160000 --- a/community-build/community-projects/scodec +++ b/community-build/community-projects/scodec @@ -1 +1 @@ -Subproject commit 18047cac1febc840e03dee91a31183d64e632222 +Subproject commit d59c0440b078292dedff10b6743d6a086f468527