Skip to content

Cyclic initialization compiles with -Yexplicit-nulls and -Ysafe-init #11262

Closed
@crater2150

Description

@crater2150

Compiler version

3.0.0-M3-bin-20201216-c8fb1fa-NIGHTLY-git-c8fb1fa

Minimized code

object A { val x: String = B.y }
object B { val y: String = A.x }

Output

Compiled with both -Yexplicit-nulls and -Ysafe-init, both fields are null:

A.x == null
B.y == null

Expectation

I expected this not to compile. I'm not sure if detecting such cycles is in scope for -Ycheck-init, but the documentation for explicit nulls suggests that -Ycheck-init catches the unsoundness caused by null in initialization.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions