Open
Description
Description
Global variables used in main.swift
are visible in functions of the module, which allows their access while uninitialized
Steps to reproduce
class Foo { let message: String = "oh no" }
func getFoo() -> Foo { foo }
let foo = getFoo()
print(foo.message)

This happens as well if getFoo()
is moved to a different file in the same module.
Expected behavior
The code should fail to compile because getFoo()
accesses an uninitialized foo
. More generally, variables in main.swift
should probably be treated like local variables in a function rather than like global variables.
Environment
- Swift compiler version info:
compnerd.org Swift version 5.11-dev (LLVM ee13eccb18b0dc4, Swift a94d22e017bd6a4)
Target: x86_64-unknown-windows-msvc
(built from main on 2023-10-27)
- Xcode version info: N/A
- Deployment target: Windows 11