Skip to content

Omitting the null check for modules in == is not correct #9655

@scabug

Description

@scabug

Since scala/scala#2954 we omit null checks when generating SomeModule == x. This is incorrect, a module dereference may return null.

class C {
  println(s"O is $O")
  val r = O == ("hi": AnyRef)
}
object O extends C

object Test {
  def main(args: Array[String]): Unit = {
    println((new C).r)
  }
}

runs as

O is null
java.lang.NullPointerException
	at C.<init>(Test.scala:10)
	at O$.<init>(Test.scala:12)
	at O$.<clinit>(Test.scala)
	at C.<init>(Test.scala:9)
	at Test$.main(Test.scala:16)
	at Test.main(Test.scala)

Related to scala/scala-dev#8 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions