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

No 'comparing unrelated types' warning for functions #9675

Closed
scabug opened this issue Feb 25, 2016 · 3 comments
Closed

No 'comparing unrelated types' warning for functions #9675

scabug opened this issue Feb 25, 2016 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Feb 25, 2016

scalac 2.11.6 compiler gives useful warnings about unrelated types comparsion for expression, method, and functions.

scalac 2.11.7 doesn't give warning for functions.

case class A(x: String)

object App {

  // No warning with 2.11.7
  val func1 = (x: A)  { x != "x" }

  // No warning with 2.11.7
  val func2  = (x: A)  { x != "x" }: Boolean

  // No warning with 2.11.7
  val func3: Function1[A, Boolean] = (x)  { x != "x" }

  // Warning in method `apply` appeared
  val func4 = new Function1[A, Boolean] {
    def apply(x: A): Boolean = { x != "x" }
  }

  // Warning appeared
  def method(x: A): Boolean = { x != "x" }

  def main(args: Array[String]) {

    // Warning appeared
    A("x") != "x"

    // No warning with 2.11.7
    val func4: Function1[A, Boolean] = (x)  { x != "x" }

    // No warning with 2.11.7
    List(A("x")).foreach((item: A)  item != "x")
  }
}

Output of the scalac 2.11.7 and 2.12.0-M3 are the same:

[warn] C:\...\App.scala:18: comparing values of types abc.A and String using `!=' will always yield true
[warn]     def apply(x: A): Boolean = { x != "x" }
[warn]                                    ^
[warn] C:\...\App.scala:22: comparing values of types abc.A and String using `!=' will always yield true
[warn]   def method(x: A): Boolean = { x != "x" }
[warn]                                   ^
[warn] C:\...\App.scala:27: comparing values of types abc.A and String using `!=' will always yield true
[warn]     A("x") != "x"
[warn]            ^
[warn] three warnings found

Output of the scalac 2.11.6 (desired behaviour)

 C:\...\App.scala:8: comparing values of types abc.A and String using `!=' will always yield true
   val func1 = (x: A) ? { x != "x" }
                            ^
 C:\...\App.scala:11: comparing values of types abc.A and String using `!=' will always yield true
   val func2  = (x: A) ? { x != "x" }: Boolean
                             ^
 C:\...\App.scala:14: comparing values of types abc.A and String using `!=' will always yield true
   val func3: Function1[A, Boolean] = (x) ? { x != "x" }
                                                ^
 C:\...\App.scala:18: comparing values of types abc.A and String using `!=' will always yield true
     def apply(x: A): Boolean = { x != "x" }
                                    ^
 C:\Users\easy\sandbox\sbt-hide-warnings\src\main\scala\icm\App.scala:22: comparing values of types abc.A and String using `!=' will always yield true
   def method(x: A): Boolean = { x != "x" }
                                   ^
 C:\Users\easy\sandbox\sbt-hide-warnings\src\main\scala\icm\App.scala:27: comparing values of types abc.A and String using `!=' will always yield true
     A("x") != "x"
            ^
 C:\Users\easy\sandbox\sbt-hide-warnings\src\main\scala\icm\App.scala:30: comparing values of types abc.A and String using `!=' will always yield true
     val func4: Function1[A, Boolean] = (x) ? { x != "x" }
                                                  ^
 C:\..\App.scala:33: comparing values of types abc.A and String using `!=' will always yield true
     List(A("x")).foreach((item: A) ? item != "x")
                                           ^
 8 warnings found
@scabug
Copy link
Author

scabug commented Feb 25, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9675?orig=1
Reporter: andy legkiy (easy)
Affected Versions: 2.11.7, 2.11.8, 2.12.0-M3

@scabug
Copy link
Author

scabug commented Feb 16, 2017

@adriaanm said:
scala/scala#5662

@scabug
Copy link
Author

scabug commented Feb 16, 2017

@adriaanm said:
Fixed by @teldosas

@scabug scabug closed this as completed Feb 16, 2017
@scabug scabug added this to the 2.12.2 milestone Apr 7, 2017
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

1 participant