[SR-3316] "Script mode" globals have internal visibility and can be accessed before initialization from other files #45904
Labels
access control
Feature → modifiers: Access control and access levels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
feature
A feature request or implementation
good first issue
Good for newcomers
swift evolution proposal needed
Flag → feature: A feature that warrants a Swift evolution proposal
Additional Detail from JIRA
md5: e092a51eda538e02ab484391d0b1b1a5
Issue Description:
Variables declared in a script default to internal visibility, like other global declarations, but this is problematic, because semantically they behave more like local variables. Another file can access the global before its initializer has even run:
In a future version of Swift, script globals should be changed to be private by default. We could possibly also allow a script global to be declared with explicit access control, which would make it visible to other files but would also have to make the variable behave more like a library global, with a
dispatch_once
-d initializer, e.g.:The text was updated successfully, but these errors were encountered: