Skip to content

Fix parents of tuple classes #13659

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

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ object TypeOps:
val doms = dominators(commonBaseClasses, Nil)
def baseTp(cls: ClassSymbol): Type =
tp.baseType(cls).mapReduceOr(identity)(mergeRefinedOrApplied)
doms.map(baseTp).reduceLeft(AndType.apply)
def meet(tp1: Type, tp2: Type) =
if !tp1.exists then tp2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is needed, we do:

val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect)

(btw, how is this different from tp.baseClasses ?)
So I would expect tp.baseType on any of the common base classes to exist, but in fact the base classes of Tuple1[(Axis, Int)] | ((Axis, Int), (Axis, Int)) contains Product2, even though Tuple1 does not extend Product2, so I think there's a bug in how we compute base classes for unions, either here or in OrType#baseClasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(btw, how is this different from tp.baseClasses ?)

Turns out it's different for Null. Since Null is also outside the inheritance hierarchy.

else if !tp2.exists then tp1
else AndType(tp1, tp2)
doms.map(baseTp).reduceLeft(meet)
}

tp match {
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i13435.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- [E029] Pattern Match Exhaustivity Warning: tests/neg/i13435.scala:7:2 -----------------------------------------------
7 | s match
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: (_), ((_, _), (_, _))

longer explanation available when compiling with `-explain`
-- Error: tests/neg/i13435.scala:8:10 ----------------------------------------------------------------------------------
8 | case (dim: Axis, size: Int) => dim // error
| ^^^^^^^^^
| trait Singleton cannot be used in runtime type tests
8 changes: 8 additions & 0 deletions tests/neg/i13435.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Axis = String&Singleton
type ShapeTuple = Tuple1[(Axis, Int)]|Tuple2[(Axis, Int), (Axis, Int)]
type Shape = (Axis, Int) |ShapeTuple


def mkSchema(s: Shape) =
s match
case (dim: Axis, size: Int) => dim // error