-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-7083] lazy properties can't have observers #49631
Comments
Possible implementation strategy: Lazy variables are turned into computed properties during type checking in TypeCheckDecl.cpp's DeclChecker::visitBoundVariable method: // Synthesize accessors for lazy, all checking already been performed.
if (VD->getAttrs().hasAttribute<LazyAttr>() && !VD->isStatic() &&
!VD->getGetter()->hasBody())
TC.completeLazyVarImplementation(VD);
// If this is a willSet/didSet property, synthesize the getter and setter
// decl.
if (VD->hasObservers() && !VD->getGetter()->getBody())
synthesizeObservingAccessors(VD, TC); The lazy variable checking happens right before observers are normally synthesized. When we create the getter/setter for lazy variables inside |
Comment by Jeff Johnson (JIRA) Strangely, this pattern currently works
even though this pattern doesn't:
|
Comment by Ray Fix (JIRA) A couple of us are looking at this at an try! Swift workshop in Japan this morning. |
Comment by Mohit Athwani (JIRA) Going to try working on this as my starter bug... Any tips from you guys? |
Comment by Mohit Athwani (JIRA) Is any body still working on this? Should I start looking into it? |
PR here: #24043 This type checks now, but causes an issue with DI. I don't think it's a DI problem, I guess I messed up something in the type checker, so need to look into that. |
@theblixguy, are you still working on this one? (I'm checking in on all the StarterBugs that haven't been touched in over a month; it's totally fine if you just haven't had time but still want to keep it.) |
I have a PR open (link above) - the only thing left to do is to figure out why DefiniteInitialization is complaining about the lazy property not being initialised when you add an observer. I’ll try to figure out today/tomorrow but I’m not very familiar with SIL so some help would be appreciated! |
Hmm it seems like that DI issue is gone, but there's still an issue with SILGen. @slavapestov since you recently did some work on lazy properties, do you mind having a look at my PR? Thank you! |
Decided to revisit this and I’ve now got it working: #31097 |
Fixed on master. @jckarter please verify using the next available snapshot! |
@swift-ci create |
Additional Detail from JIRA
md5: 97bf74aed4a6125643746316d5582ad4
Issue Description:
The compiler won't let you put didSet/willSet observers on a lazy property. Since lazy properties are supposed to look and feel like stored properties, they should be able to have observers.
The text was updated successfully, but these errors were encountered: