-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-12043] Top-level variables in REPL #54479
Comments
|
It's not documented, and it allows for the creation of undefined behavior: the value you get initialized with is usually the zero bitpattern, so you can create ill-typed null pointers out of thin air. |
|
@swift-ci create |
|
Yes, this is intentional. |
|
More generally, the REPL does a lot of stuffs that are not really kosher from a language perspective because it was originally thought as a tool to "experiment". If you ask me, the semantics of the REPL and the one of the language should be a 1:1 mapping, but it's really hard to get to that point without breaking, e.g. existing playgrounds. |
|
Comment by Steven Van Impe (JIRA) If Swift is going to support more platforms in the future, the REPL will become an important teaching tool, as the point of entry for new learners. With that in mind, I hope the REPL will evolve to match the language 1:1 and become more reliable, as issues like this, and SR-8690, and SR-1743, can easily leave a bad impression on new learners. |
Environment
Swift 5.1.3
Additional Detail from JIRA
md5: 3aa2a9d5cebddd4796f89d36aa578bf6
Issue Description:
I've noticed that the REPL assigns default values when declaring (but not initializing) a variable:
Is this behavior documented somewhere? Is this even intentional, or is it just showing the contents of memory?
I believe this is a recent change, as I remember seeing a "top-level variable must be initialized" error for at least some of these examples with Swift 4.
The text was updated successfully, but these errors were encountered: