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
swift-ci opened this issue
Oct 31, 2019
· 1 comment
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselffeatureA feature request or implementation
structS {
leti: Intinit(_i: Int = 5) {
self.i = i
}
init() {
i = 6
}
}
print(S().i) // prints 6
This is dangerous, because if S.init() were deleted, the program would still compile; however, S().i would now evaluate to 5.
Conversely, if init() didn't already exist, and was added later, especially in another module as a convenience init, there might be difficult to debug issues in modules it was exposed to, as which init was called might be inconsistent depending on the location of the new init() function and which modules depended on it (I haven't checked this, but it seems likely).
For these reasons, I believe that this program should be rejected by the compiler.
The text was updated successfully, but these errors were encountered:
This would be source-breaking, so it would have to go through the Swift Evolution Process. SR-11095 talks about a warning on the default argument only, but that wouldn't handle the extension-in-another-module case brought up here.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselffeatureA feature request or implementation
Environment
Swift 5.1.
Additional Detail from JIRA
md5: 5d92be961dfad3959beb2f10b93a6c76
relates to:
Issue Description:
The Swift compiler accepts the following code:
This is dangerous, because if
S.init()
were deleted, the program would still compile; however,S().i
would now evaluate to 5.Conversely, if
init()
didn't already exist, and was added later, especially in another module as a convenience init, there might be difficult to debug issues in modules it was exposed to, as which init was called might be inconsistent depending on the location of the newinit()
function and which modules depended on it (I haven't checked this, but it seems likely).For these reasons, I believe that this program should be rejected by the compiler.
The text was updated successfully, but these errors were encountered: