Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use upper bound of effectively sealed abstract types in exhaustivity checking #23909

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

Open
nox213 wants to merge 3 commits into scala:main
base: main
Choose a base branch
Loading
from nox213:fix/i23620
Open
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
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@ object SpaceEngine {
else NoType
}.filter(_.exists)
parts
case tref: TypeRef if tref.symbol.isAbstractOrAliasType && !tref.info.hiBound.isNothingType =>
rec(tref.info.hiBound, mixins)
case _ => ListOfNoType
end rec

Expand Down Expand Up @@ -853,7 +855,14 @@ object SpaceEngine {
}) ||
tpw.isRef(defn.BooleanClass) ||
classSym.isAllOf(JavaEnum) ||
classSym.is(Case)
classSym.is(Case) ||
(tpw.isInstanceOf[TypeRef] && {
val tref = tpw.asInstanceOf[TypeRef]
if (tref.symbol.isAbstractOrAliasType && !tref.info.hiBound.isNothingType)
isCheckable(tref.info.hiBound)
else
false
})

!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
&& !sel.tpe.hasAnnotation(defn.RuntimeCheckedAnnot)
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i23620.scala
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Foo
trait Bar

type FooOrBar = FooOrBar.Type
object FooOrBar:
opaque type Type <: (Foo | Bar) = Foo | Bar

def bar: FooOrBar = new Bar {}

trait Buz

@main def main =
val p: FooOrBar | Buz = FooOrBar.bar

p match
case _: Foo => println("foo")
case _: Buz => println("buz")
case _: Bar => println("bar")
16 changes: 16 additions & 0 deletions tests/warn/i23620b.check
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i23620b.scala:20:2 --------------------------------------------
20 | p match // warn
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Bar
|
| longer explanation available when compiling with `-explain`
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i23620b.scala:23:2 --------------------------------------------
23 | p2 match { //warn
| ^^
| match may not be exhaustive.
|
| It would fail on pattern case: _: Bar
|
| longer explanation available when compiling with `-explain`
25 changes: 25 additions & 0 deletions tests/warn/i23620b.scala
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
trait Foo
trait Bar

type FooOrBar = FooOrBar.Type
object FooOrBar:
opaque type Type <: (Foo | Bar) = Foo | Bar

def bar: FooOrBar = new Bar {}

type OnlyFoo = OnlyFoo.Type
object OnlyFoo:
opaque type Type <: (Foo | Bar) = Foo

def foo: OnlyFoo = new Foo {}

@main def main =
val p: FooOrBar= FooOrBar.bar
val p2: OnlyFoo = OnlyFoo.foo

p match // warn
case _: Foo => println("foo")

p2 match { //warn
case _: Foo => println("foo")
}
Loading

AltStyle によって変換されたページ (->オリジナル) /