Skip to content

Check for symbol existence when working with GADT bounds in TypeComparer #6431

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 4 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2107,8 +2107,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
}

override def gadtBounds(sym: Symbol)(implicit ctx: Context): TypeBounds = {
footprint += sym.typeRef
super.gadtBounds(sym)
if (!sym.exists) null
else {
footprint += sym.typeRef
super.gadtBounds(sym)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC that the problem is with NoSymbol.typeRef exploding, I'd prefer

if (sym.exists) footprint += sym.typeRef
super.gadtBounds(sym)

instead, because 1) this matters for logging 2) it should ultimately be the business of GadtConstraint to decide what to return for unconstrained symbols.

Otherwise LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That looks fine.

There's similar code in the neighbouring gadtAddLowerBound and gadtAddUpperBound ... make the same change there as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone ahead and done that. Will merge when green.

}

override def gadtAddLowerBound(sym: Symbol, b: Type): Boolean = {
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/dep-match.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Test {
type Foo = Int { type U }
type Bar[T] = T match {
case Unit => Unit
}
inline def baz(foo: Foo): Unit = {
val v: Bar[foo.U] = ???
}
}