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
Apple Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 24a0c3d)
Target: x86_64-apple-macosx10.9
(03/01 snapshot)
Additional Detail from JIRA
Votes
6
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 60d55ae3d3ed11203ed60b6986237ce0
is duplicated by:
SR-4395 Incomplete initialization of self results in confusing error messages with @autoclosure functions
SR-7584 Seemingly incorrect "Constant 'self.X' captured before being initialized" compiler error in struct initializer
SR-7990 Using && on instance property in initializer results in confusing/incorrect error message
SR-11493 Can't use property of self before initialization when using the && operator
Issue Description:
When checking a conditional for an if statement in a initializer, specifying a member variable in the second or subsequent component will cause the compiler to complain that self was captured by a closure before all members were initialized.
The following code snippet demonstrates the problem:
class A {
var a: Int?
var b: Int
init() {
a = 4
var c: String?
if c == nil && a == nil {
print("in")
}
b = 4
}
}
Interestingly, switching the ordering of the c and a nil checks will cause the error to go away.
`||` is in the same boat, and optionals are not required. Quite confusing!
classA {
vara: Intvarb: Intinit() {
a = 4// likely actually set to some init parameterifa == 4 {
print("OK")
}
ifa == 4 || a == 5 { // "self captured by a closure" print("not OK")
}
b = 4
}
}
I really wasn't expecting this to fail. The error confused me as well. I kept staring at my code, wondering where the closure was. I assumed I got the error because I was using a property to initialize another one, but the error didn't mention the previously initialized property (bool1 or userIsHost), only the current one (bool2 or userHasAutoApprove)
Environment
Apple Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 24a0c3d)
Target: x86_64-apple-macosx10.9
(03/01 snapshot)
Additional Detail from JIRA
md5: 60d55ae3d3ed11203ed60b6986237ce0
is duplicated by:
Issue Description:
When checking a conditional for an if statement in a initializer, specifying a member variable in the second or subsequent component will cause the compiler to complain that self was captured by a closure before all members were initialized.
The following code snippet demonstrates the problem:
Interestingly, switching the ordering of the c and a nil checks will cause the error to go away.
I created a snapshot of the issue in the IBM Sandbox: http://swiftlang.ng.bluemix.net/#/repl/fc77261825ff05d35c3b3dbde1259ed9c9c0366688b3dc1f87216ba6ec4e75ae
The text was updated successfully, but these errors were encountered: