Skip to content

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

Closed
scala/scala
#10395
@som-snytt

Description

@som-snytt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions