Swift: Swift tries to resolve static properties instead of perfectly valid globals when it makes no sense
| Originator: | rix.rob | ||
| Number: | rdar://21474006 | Date Originated: | 20-Jun-2015 10:02 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-7-beta (7A120f) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Code in instance methods attempts to resolve static properties instead of globals by the same name. This is dumb and invalid.
Steps to Reproduce:
1. This code:
struct S {
static var f: ()
func g() {
let h: () -> Int = f
}
}
func f() -> Int {
return 0
}
Expected Results:
should compile
Actual Results:
but gives a spurious dumb error:
boom.swift:5:22: error: 'S' does not have a member named 'f'
let h: () -> Int = f
^
Regression:
Doesn’t happen if S.f doesn’t exist.
Doesn’t happen if S.f is a static func.
Does happen if S.f is a static property of function type, e.g. static let f: () -> Int = { 1 }
Pretty sure this has always happened.
You can resolve f in the outer scope with ModuleName.f but what a nuisance.
Notes:
The error message is particularly dumb; yes, it’s true S does not have a member named 'f'—so don’t try to use it! Argh.
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!