Swift: local variable declaration shadows property with the same name even before declaration statement
| Originator: | sash | ||
| Number: | rdar://22872819 | Date Originated: | 27-Sep-2015 10:21 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.0 (7A220) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Function body containing variable declaration seems to shadow class property with the same name (when addressed without `self.` prefix)
Steps to Reproduce:
Consider following code.
class Class {
var property: String?
func function() {
if property == nil { // use of local variable ‘property’ before its declaration
return
}
let property = “String”
self.property = property
}
}
Expected Results:
`if property == nil` should refer to the property not to the constant declared further in the function body
Actual Results:
Seems like `let property` declared towards the end of the function shadows the property even before declaration.
Regression:
referring to the property using `self.property` works as expected
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!