Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

ContainsTypeMismatch false positive when subtype relationship is inverted #54

Open
vdichev opened this issue Mar 30, 2017 · 0 comments
Open

Comments

@vdichev
Copy link
Contributor

vdichev commented Mar 30, 2017

To demonstrate the problem:

scala> class A; class B extends A
defined class A
defined class B

scala> val b = new B; val a: A = b
b: B = B@3358f363
a: A = B@3358f363

scala> List(a).contains(b)
res9: Boolean = true

scala> List(b).contains(a)
:16: warning: [ContainsTypeMismatch] List[B].contains(A) will probably return false, since the collection and target element are of unrelated types.
List(b).contains(a)
^
res10: Boolean = true

The warning shouldn't be raised because it's possible for a List of B to contain an element of type A which is a supertype (not subtype) of B- it's obvious that it does return true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant