-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
aeeb14b
Fix #5494: Spurious unchecked warning when type testing an alias
smarter 3991198
Fix type test warning involving applied types
smarter b1a9fd7
Add unchecked marks for technically unsafe type tests
smarter 7e30d84
Move tests
liufengyun d61eb85
Handle GADT bounds in isInstanceOf type test
liufengyun 77bd0cc
Add test
liufengyun 891db3c
Restore original spec
liufengyun 2531e18
Add test for Tree | Context => Tree
liufengyun 58f506b
Add missing variance annotation
liufengyun 10169b1
Add test for Tree | (Context => Tree)
liufengyun 31c751f
Fix unchecked warnings in compiler
liufengyun 77e96cd
Fix typo in comment
liufengyun b5ae277
Fix unchecked warning in language server
liufengyun 1cb965a
Add more test case
liufengyun 2e028af
Add documentation for code
liufengyun 33094bf
Address review: add comment
liufengyun fb672e5
Address review: rename isClassDetermined to typeArgsTrivial
liufengyun 4a5ab5a
Address review: code refactoring
liufengyun 841d191
Add test case for type lambda
liufengyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 67 additions & 67 deletions
134
compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
object Test1 { | ||
trait Tree[-T] | ||
|
||
class JavaSeqLiteral[T] extends Tree[T] | ||
|
||
trait Type | ||
|
||
class DummyTree extends JavaSeqLiteral[Any] | ||
|
||
def foo1(tree: Tree[Type]) = | ||
tree.isInstanceOf[JavaSeqLiteral[Type]] // error | ||
|
||
foo1(new DummyTree) | ||
} | ||
|
||
object Test2 { | ||
trait Tree[-T] | ||
|
||
class JavaSeqLiteral[-T] extends Tree[T] | ||
|
||
trait Type | ||
|
||
class DummyTree extends JavaSeqLiteral[Any] | ||
|
||
def foo1(tree: Tree[Type]) = | ||
tree.isInstanceOf[JavaSeqLiteral[Type]] | ||
|
||
foo1(new DummyTree) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
object Test1 { | ||
trait Tree | ||
trait Context | ||
|
||
def foo1(myTree: Tree | (Context => Tree)) = | ||
println(myTree.isInstanceOf[Tree]) | ||
|
||
def foo2(myTree: Tree | (Context => Tree)) = | ||
myTree match | ||
case treeFn: (Context => Tree) => // error | ||
case _ => | ||
|
||
def foo3(myTree: Tree | (Context => Tree)) = | ||
myTree match | ||
case treeFn: (_ => _) => // ok | ||
case _ => | ||
} | ||
|
||
object Test2 { | ||
trait Tree[-T] | ||
trait Context | ||
|
||
trait Type | ||
|
||
def foo1(myTree: Tree[Type] | (Context => Tree[Type])) = | ||
println(myTree.isInstanceOf[Tree[Type]]) // error | ||
/* class DummyTree extends Tree[Nothing] with (Context => Tree[Type]) */ | ||
|
||
def foo2(myTree: Tree[Type] | (Context => Tree[Type])) = | ||
myTree match | ||
case treeFn: (Context => Tree[Type]) => // error | ||
case _ => | ||
|
||
def foo3(myTree: Tree[Type] | (Context => Tree[Type])) = | ||
myTree match | ||
case treeFn: (_ => _) => // ok | ||
case _ => | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
trait A[T] | ||
trait B[T] extends A[T] | ||
|
||
object Test { | ||
def foo(x: ([X] =>> A[X])[Any]) = x match { | ||
case x: ([X] =>> B[X])[Any] => | ||
case _ => | ||
} | ||
|
||
def bar(x: ([X] =>> A[X])[Any]) = x match { | ||
case x: ([X] =>> B[Nothing])[Any] => // error | ||
case _ => | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: