Skip to content

"Reference to uninitialized value" warning not produced for more complicated reference patterns #367

Closed
@cnestor

Description

@cnestor

Hey guys! Not sure how hard this would be to fix, but I thought I would bring it up.

//produces compiler warning
class C1 {
  val x = y
  val y = 1
}

//no warning :(
class C2 {
  val x = getY
  val y = 1
  def getY = y
}

//no warning either :(
trait T {
  val y: Int
  val x: Int = y
}

class C3 extends T {
  val y = 1
}

This is a really easy thing to do accidentally if you're moving things around and it can lead to a class that throws a NullPointerException whenever it is instantiated.

Related - #221
IMO it would be better to produce an error than a warning in general, especially since classes/strings/collections/misc non-Int values default to null, which seems to run very counter to the spirit of Scala. ¯\_ (ツ) _/¯

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions