Skip to content

Fix #5970: suppress spurious warning in isInstanceOf check #5985

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 2 commits into from
Mar 20, 2019
Merged
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: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,17 @@ object SymDenotations {
(symbol eq defn.NothingClass) ||
(symbol eq defn.NullClass) && (base ne defn.NothingClass))

/** Is it possible that a class inherits both `this` and `that`?
*
* @note The test is based on single-class inheritance and the closed
* hierarchy of final classes.
*
* @return The result may contain false positives, but never false negatives.
*/
final def mayHaveCommonChild(that: ClassSymbol)(implicit ctx: Context): Boolean =
!this.is(Final) && !that.is(Final) && (this.is(Trait) || that.is(Trait)) ||
this.derivesFrom(that) || that.derivesFrom(this.symbol)

Copy link
Contributor Author

@liufengyun liufengyun Feb 25, 2019

Choose a reason for hiding this comment

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

@OlivierBlanvillain I'm not sure how this fits into your refactoring. Maybe we can delay this PR until the refactoring is merged.

final override def typeParamCreationFlags: FlagSet = ClassTypeParamCreationFlags

/** Hook to do a pre-enter test. Overridden in PackageDenotation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ object TypeTestsCasts {
recur(tp1, P) && recur(tp2, P)
case _ =>
// first try withou striping type parameters for performance
X.classSymbol.exists && P.classSymbol.exists && !X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass) ||
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) ||
isClassDetermined(stripTypeParam(X), tpe)(ctx.fresh.setNewTyperState())
}
Expand Down
12 changes: 12 additions & 0 deletions tests/pos-special/fatal-warnings/i5970.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Test extends App {
case class Foo[T](t: T)

def foo[T](ft: Unit|Foo[T]): T = {
ft match {
case Foo(t) => t
case () => ???
}
}

foo(Foo(23))
}