scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

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

Closed som-snytt closed 1 year ago

som-snytt commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

See https://github.com/scala/bug/issues/5537