Last active
October 10, 2017 21:46
-
-
Save slavapestov/2dd7e599154b4b5992c5a6797ce06235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct S { | |
let x: Int | |
init(x: Int) { self.x = x } | |
// This is allowed | |
init(x2: Int) { | |
self.init(x: x2) | |
} | |
// This is also allowed | |
init(x3: Int) { | |
self = S(x: x2) | |
} | |
// This is also allowed | |
init(x4: Int) { | |
self.init(x: x4) | |
self = S(x: x4) | |
} | |
// This is also allowed | |
init(x5: Int) { | |
self = S(x: x5) | |
self = S(x: x5) | |
} | |
// But this is not | |
init(x6: Int) { | |
self.init(x: x6) | |
self.init(x: x6) | |
} | |
} | |
// Either x4, x5 and x6 should all be banned, or x6 should work. | |
// The reason is that I noticed that this doesn't work: | |
init(y: Bool) { | |
if y { | |
self = S(x: 0) | |
} else { | |
self.init(x: 1) | |
} | |
} | |
// The fix is quite simple; the SIL for 'self = ...' and 'self.init' is | |
// already identical, only the AST differs. However, treating them | |
// identically in definite initialization exposes the issue at the top | |
// of the gist. We need to figure out if we want to allow multiple | |
// initialization of 'self' or not, regardless of how it was initialized. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment