Skip to content

Bad warning text: comparing values of types type and Array[B] #12785

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

Closed
som-snytt opened this issue May 10, 2023 · 2 comments · Fixed by scala/scala#10395
Closed

Bad warning text: comparing values of types type and Array[B] #12785

som-snytt opened this issue May 10, 2023 · 2 comments · Fixed by scala/scala#10395
Labels
Milestone

Comments

@som-snytt
Copy link

Reproduction steps

Scala version: 2.13.10

scala> Predef.eq("")
                ^
       warning: comparing values of types type and String using `eq` will always yield false
val res1: Boolean = false

Problem

What is it trying to render as the type type?

The context was a bit tricky:

import scala.Predef._

final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
  def startsWith[B >: A](that: Array[B]): Boolean = eq(that)
  //def f[B >: A](that: Array[B]): Boolean = Predef.eq(that)
}

Masculine swagger made me try writing eq(that) instead of the usual this.eq(that), erroneous for xs.eq(that).

Proper style dictates that all universal (plus AnyRef) methods require an explicit receiver, because otherwise you never know.

Note that without the import (which exists for reasons of hygiene, ironically), Note that ArrayOps extends Any, not AnyRef. because the methods are not root-imported from Predef.

@som-snytt
Copy link
Author

scala.Predef.type presumably.

The doc says

    /** Conditions where we omit the prefix when printing a symbol, to avoid
     *  unpleasantries like Predef.String, $read.$iw.Foo and <empty>.Bippy.
     */
    final def isOmittablePrefix

@som-snytt
Copy link
Author

See #5537

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

Successfully merging a pull request may close this issue.

2 participants