Skip to content

-Ycheck-init promoting value to fully initialised when passed to array #9664

Closed
@bishabosha

Description

@bishabosha

Minimized code

// compile with -Ycheck-init
object Wrap1 {                                                                              
  class E
  object E {
    final val A = E()
    val $values = Array(A)
  }
}
object Wrap2 {                                                                              
  class E
  object E {
    final val A = E()
    val ref = A
  }
}

Output

-- Warning: initcheck.scala:5:23 ----------------------------------
5 |    val $values = Array(A)
  |                        ^
  |Promoting the value under initialization to fully-initialized. Calling trace:
  | -> val $values = Array(A)	[ initcheck.scala:5 ]
1 warning found

Expectation

I thought that directly referencing the value should have the same behaviour as passing it to an array constructor

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions