[pigeon] Fixes bug with mixmatch of nndb and nested types of objc.#2157
[pigeon] Fixes bug with mixmatch of nndb and nested types of objc.#2157gaaclarke merged 8 commits intoflutter:mainfrom
Conversation
| } | ||
| return '[$className fromMap:GetNullableObject($dict, @"${field.name}")]'; | ||
| final String mapExpression = 'GetNullableObject($dict, @"${field.name}")'; | ||
| return '($mapExpression ? [$className fromMap:$mapExpression] : nil)'; |
There was a problem hiding this comment.
Duplicating evaluation of the whole expression in the common case seems needlessly inefficient. Why not just make fromMap:nil return nil, which is less generated code and more efficient at runtime than this?
There was a problem hiding this comment.
Changing the contract for functions like that when we don't have support from the compiler has been fraught in the past. I would be better off storing the variable. It requires shifting the dart code around though and generating unique symbols. I'll look into it.
There was a problem hiding this comment.
Can you elaborate on the concern here? It's a private method, so we control all calls to it. We call it in exactly two places AFAICT:
readValueOfType:, which explicitly returns a nullable value- Here, where returning
nilis explicitly the behavior we want.
There was a problem hiding this comment.
Yea, it's not so easy to reason about its usage when we are generating code. I've introduced bugs when changing these before. The function can be used in other contexts where it is expected to return a non-null value (ex a nonnull nested object). It's best to avoid it.
There was a problem hiding this comment.
Done. I added a nullable variant that can be used in this case (one sec I'll add an integration test too).
There was a problem hiding this comment.
The new method should be used to simplify line 925 as well.
There was a problem hiding this comment.
objc_generator.dart:925? That's the definition of the new method. You talking about somewhere else?
There was a problem hiding this comment.
Sorry, I was on a phone and confused myself about the context while searching for the other location.
I'm still not clear on why we can't replace https://github.com/flutter/packages/blob/e6d5f869bf8d5c332e30231424c1493b380c5d4a/packages/pigeon/lib/objc_generator.dart#L265 with this (which is the only other use of toMap:). You said "The function can be used in other contexts where it is expected to return a non-null value", but that usage is a function that returns a (nullable id). I don't understand how an explicitly nullable function can be expected to return a non-null value; that means you are expecting a function to behave differently than its explicit documented behavior, which is a recipe for disaster. If there is code that is calling readValueOfType: but requires that it return a non-null value, then the calling code is wrong and we should fix it.
ab02c1f to
60774a7
Compare
|
Ah, looks like I broke some dart tests. One sec. |
60774a7 to
f8ac5cf
Compare
Should be good now. |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
LGTM with comment nit.
I still don't think we should have the second method at all, vs just changing fromMap:, but we can revisit that later.
There was a problem hiding this comment.
I think this should have a comment saying that it's non-nullable to test non-nullable fields nested inside of nullable fields, so someone doesn't "fix" it later.
b3b07c9 to
a64538a
Compare
a64538a to
761a271
Compare
|
This pull request is not suitable for automatic merging in its current state.
|
2dcd121 to
c699272
Compare
c699272 to
a361f31
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
a361f31 to
eb8293a
Compare
eb8293a to
2891733
Compare
2891733 to
3d515c7
Compare
|
I'm not sure what happened with github. I merged before the fuchsia_ctl step finished since it takes forever and isn't related. Github however is listing the windows step as not passing, that wasn't the case, it passed here: https://ci.chromium.org/ui/p/flutter/builders/try/Windows%20custom_package_tests%20master%20-%20packages/987/overview |
fixes flutter/flutter#104871
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.