-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #5494: Spurious unchecked warning when type testing an alias #8808
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
Changes from 9 commits
aeeb14b
3991198
b1a9fd7
7e30d84
d61eb85
77bd0cc
891db3c
2531e18
58f506b
10169b1
31c751f
77e96cd
b5ae277
1cb965a
2e028af
33094bf
fb672e5
4a5ab5a
841d191
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,10 +105,9 @@ object TypeTestsCasts { | |
| debug.println("P1 : " + P1.show) | ||
| debug.println("X : " + X.show) | ||
|
|
||
| P1 <:< X // constraint P1 | ||
| P1 <:< X | ||
smarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // use fromScala2x to avoid generating pattern bound symbols | ||
| maximizeType(P1, span, fromScala2x = true) | ||
| maximizeType(P1, span, fromScala2x = false) | ||
smarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| val res = P1 <:< P | ||
| debug.println("P1 : " + P1.show) | ||
|
|
@@ -117,7 +116,7 @@ object TypeTestsCasts { | |
| res | ||
| } | ||
|
|
||
| def recur(X: Type, P: Type): Boolean = (X <:< P) || (P match { | ||
| def recur(X: Type, P: Type): Boolean = (X <:< P) || (P.dealias match { | ||
| case _: SingletonType => true | ||
| case _: TypeProxy | ||
| if isAbstract(P) => false | ||
|
|
@@ -138,8 +137,8 @@ object TypeTestsCasts { | |
| 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()) | ||
| isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState().setFreshGADTBounds) || | ||
|
||
| isClassDetermined(stripTypeParam(X), tpe)(ctx.fresh.setNewTyperState().setFreshGADTBounds) | ||
| } | ||
| case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) | ||
| case OrType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class Test { | ||
| trait A[+T] | ||
| class B[T] extends A[T] | ||
|
|
||
| class C | ||
| class D extends C | ||
|
|
||
| def quux(a: A[C]): Unit = a match { | ||
| case _: B[C] => // error!! | ||
| } | ||
|
|
||
| quux(new B[D]) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class A | ||
| class B | ||
|
|
||
| type AorB = A | B | ||
|
|
||
| def foo(any: Any) = any match { | ||
| case aorb: AorB => | ||
| case _ => | ||
| } | ||
|
|
||
| def bar[T](x: List[T]) = x.isInstanceof[List[Int]] // error | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| trait Tree | ||
| trait Context | ||
|
|
||
| def foo(myTree: Tree | (Context => Tree)) = | ||
| println(myTree.isInstanceOf[Tree]) | ||
| myTree match | ||
| case treeFn: (Context => Tree) => // error | ||
| case _ => | ||
|
|
||
| def bar(myTree: Tree | (Context => Tree)) = | ||
| myTree match | ||
| case treeFn: (_ => _) => // ok | ||
| case _ => |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class A[-T] | ||
| class B[T] extends A[T] | ||
|
|
||
| object Test { | ||
| def foo(x: A[Null]) = x match { | ||
| case x: B[Null] => | ||
| case _ => | ||
| } | ||
| } | ||
|
|
||
| def bar[T](x: List[T]) = x.isInstanceof[List[Int]] // error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good for uniformity but why would this make any difference for type test safety warnings ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code shows why it matters: