[SR-7990] Using && on instance property in initializer results in confusing/incorrect error message #50523
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
definite initialization
Environment
Tested in Swift 4.2 on the Xcode 10 beta.
Additional Detail from JIRA
md5: 29a1e02d86cbd1e221018c402b373fab
duplicates:
Issue Description:
The autoclosure of the second argument of Swift's && implementation has resulted in an error which at best is incredibly confusing, and in my opinion, actually incorrect. The code is as follows:
which results in the following error:
If I had not already been aware of the fact that the second argument of && is autoclosure'd, this error message would have been truly baffling. I never would have thought to look into the definition of the && operator as the source of the error until I had invested a long time debugging.
But this shouldn't even be an error at all! I've already initialized self.prop2, so I should be able to use it to initialize my other properties without having to resort to this workaround:
IMO, the compiler should be smart enough to realize that either we should not try to autoclosure this expression since it would capture self in an initializer, OR recognize that it only needs to capture properties of self that have already been initialized.
If this is undesired/infeasible at the moment, then the error message should at least give some indication that the reason for the capture is an autoclosure of the && operator, and that the issue is that all of self has to be captured. Note that if we make Test into a class, the error message is marginally better:
The current state of affairs makes it seem like there is somehow a closure capturing the left hand side of the = operator above.
The text was updated successfully, but these errors were encountered: