You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
Yes, this is intentional.
The whole story is a little messy here, we should really reconsider if we get to reply the REPL to properly match the semantics of the language.
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.
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: