Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Queue Events for better media uploads #2366
Queue Events for better media uploads #2366
Changes from 9 commits
83541c1
f487990
e01ea90
880478c
04e3038
85c1770
fb8dad5
d59599a
7f1bc5a
7997acb
8f13252
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry! I meant the warning on this line. I wrote the comment but it disappeared somehow (second time that happens to me this week ¯\_(ツ)_/¯ )
The warning says
Coercion of implicitly unwrappable value of type 'Any?' to 'Any' does not unwrap optional
Would the override still work if we change the optionality of the parameters?
Actually on a second look, that
Any!
looks quite dangerous. This might crash if any queued event had no body.It would be great if
name
were not optional andbody
is an actual non-implicitly-unwrapped optional, but open to possibilities too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a test and it doesn't crash.
Any
seems to accept a nil value even if it's not an optional itself (?)But still... I wouldn't trust the runtime completely with this 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I wouldn't have expected that. Does that mean the struct's default initializer is not actually force-unwrapping the value? When you tested with a
nil
, do you know if theGutenbergEvent
was initialized, or did the code branch directly to thesuper.sendEvent
?Update:
In a playground, I just tried this:
And there are no errors in runtime. Interestingly, when I use
AnyObject
, I get a run-time crash (Terminated by signal 4), just initializing the struct:Perhaps there is some subtlety with permissiveness afforded for potential value or reference types? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kinds of make sense in a way that
Optional
is basically aValue type
, and we are passingOptional<>.none
asAny
.And
AnyObject
wouldn't accept it since it expectsReference
types only, so it will try to unwrap the optional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation Eduardo! I also found this explanation, which is just as you mentioned. The discussion is interesting because it explains why you cannot directly assign nil to a var with type Any, since there is no inferred type for the generic in the Optional. That there is no error in the above case was surprising to me, but this explains it (kind of a language design edge case, I suppose).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So @mkevins @chipsnyder , what do you think: Should we avoid this edge case?
I think it would be good to try avoid it, but since it's clear now that it won't crash, maybe it's not a blocker for this PR. Still it would be good to clear the warning 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that is weird! Thanks for confirming though.
I totally missed this error thank you for catching it. Also thank you both for the investigation and knowledge share. That's really interesting on how
Any
andOptionals
interact.Yeah this is neat, sometimes it's easy to forget that language design has its own edge cases to deal with.
To me, it seems like an easy fix to adjust. So I'll make that tweak today and push up a commit to this PR here shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually an interesting situation. @etoledom I didn't run into the warning that you were seeing so I was wondering if it was a runtime flag, but I wasn't able to see it at runtime either.
I do think it would be a good idea to be explicit about the optionality of the event parameters though so I did an update to address that. If you don't mind will you let me know if it fixes the warning?
XCode 11.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, I didn't see the warning either (but I was exploring the code via the WordPress-iOS project, so I wonder if that's a factor?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, you will see it if you run the gutenberg example project on Xcode.
EDIT:
The last change from 8f13252 solved the warning!
Thank you @chipsnyder for the update 🙏