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
Apparently this corner case is not captured by the compiler with an 'Invalid redeclaration of 'test'' error. We can shadow optional-members in a custom extension and make them non-optional:
I believe this is deliberate; you're allowed to shadow things from other modules in your own module, which is important if someone introduces a new decl in their library but you want to continue using yours. This also works:
import A
extension P {
var test: Int? {
return nil
}
}
Arguably, though, we could have a warning or something at first, and then you have to add an attribute to say "yes, I know I'm shadowing this".
Spent an hour trying to figure out why my code wasn’t working and this was the culprit. It would be really useful to have warning diagnostic when you have an optional protocol requirement satisfied by a default implementation and the conforming type’s implementation is non-optional. An attribute to silence the warning sounds reasonable, maybe something like “@shadowImplementation” (open to suggestions).
Additional Detail from JIRA
md5: 06ddb1a8670e4226e673abac6618b2cb
Issue Description:
Apparently this corner case is not captured by the compiler with an 'Invalid redeclaration of 'test'' error. We can shadow optional-members in a custom extension and make them non-optional:
The text was updated successfully, but these errors were encountered: