Skip to content
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

Unexpected warning when comparing with java.lang.Object #9953

Closed
scabug opened this issue Oct 7, 2016 · 6 comments
Closed

Unexpected warning when comparing with java.lang.Object #9953

scabug opened this issue Oct 7, 2016 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 7, 2016

When I compare a java.lang.Object with a Scala type, the Scala compiler report the following warning:

Object and com.thoughtworks.binding.Binding.BindingSeq[String] are unrelated: they will most likely never compare equal

The warning is incorrect. The comparison does return true for my case.

@scabug
Copy link
Author

scabug commented Oct 7, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9953?orig=1
Reporter: @Atry
Affected Versions: 2.11.8
See #8965

@scabug
Copy link
Author

scabug commented Oct 7, 2016

@SethTisue said:
Is it possible to reproduce the problem in a small, self-contained project or code snippet?

@scabug
Copy link
Author

scabug commented Oct 7, 2016

@som-snytt said:

$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> val e = new java.util.EventObject("hi")
e: java.util.EventObject = java.util.EventObject[source=hi]

scala> e.getSource
res0: Object = hi

scala> e.getSource == "hi"
res1: Boolean = true

scala> trait X extends Any
defined trait X

scala> val x = null.asInstanceOf[X]
x: X = null

scala> e.getSource == x
<console>:15: warning: Object and X are unrelated: they will most likely never compare equal
       e.getSource == x
                   ^
res2: Boolean = false

scala> val o = new Object
o: Object = java.lang.Object@6aaa5eb0

scala> o == x
<console>:15: warning: Object and X are unrelated: they will most likely never compare equal
       o == x
         ^
res3: Boolean = false

scala> 

@scabug
Copy link
Author

scabug commented Oct 8, 2016

@Atry said:

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.

scala> trait X extends Any 
defined trait X

scala> object O extends X 
defined object O

scala> (O: Object) == (O: X) 
<console>:14: warning: Object and X are unrelated: they will most likely never compare equal
       (O: Object) == (O: X)
                   ^
res0: Boolean = true

@scabug
Copy link
Author

scabug commented Oct 8, 2016

@som-snytt said:
Any Hall. Isn't she lubly?

@scabug
Copy link
Author

scabug commented Oct 8, 2016

@som-snytt said:
scala/scala#5449

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

No branches or pull requests

2 participants