-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pigeon] fix swift nsnull casting crash #3545
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
Changes from 1 commit
574ee0b
46ca75e
e350040
3d31aff
3be7eb1
ef111ee
6d5271f
a4625f8
29ac0ec
4a7b408
d1d9c6f
241f0e3
8d356cc
04dfdbd
ed57271
1bd3afa
d0f9b86
fab7ca3
2e2d337
5b39dbe
cbb8e0b
7fa0f7d
b0c7653
740abd8
748a0bb
d8f5fe3
06ab71e
547ed02
367009e
cdf35ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,11 +179,11 @@ import FlutterMacOS | |
| final String listValue = 'list[$index]'; | ||
|
|
||
| _writeDecodeCasting( | ||
| root, | ||
| indent, | ||
| listValue, | ||
| field.name, | ||
| field.type, | ||
| root: root, | ||
| indent: indent, | ||
| value: listValue, | ||
| variableName: field.name, | ||
| type: field.type, | ||
| field: field, | ||
| customClassNames: customClassNames, | ||
| customEnumNames: customEnumNames, | ||
|
|
@@ -320,7 +320,12 @@ import FlutterMacOS | |
| } else { | ||
| indent.addScoped('{ response in', '}', () { | ||
| _writeDecodeCasting( | ||
| root, indent, 'response', 'result', func.returnType); | ||
| root: root, | ||
| indent: indent, | ||
| value: 'response', | ||
| variableName: 'result', | ||
| type: func.returnType, | ||
| ); | ||
| indent.writeln('completion(result)'); | ||
| }); | ||
| } | ||
|
|
@@ -436,7 +441,12 @@ import FlutterMacOS | |
| _getSafeArgumentName(index, arg.namedType); | ||
| final String argIndex = 'args[$index]'; | ||
| _writeDecodeCasting( | ||
| root, indent, argIndex, argName, arg.type); | ||
| root: root, | ||
| indent: indent, | ||
| value: argIndex, | ||
| variableName: argName, | ||
| type: arg.type, | ||
| ); | ||
| if (arg.label == '_') { | ||
| methodArgument.add(argName); | ||
| } else { | ||
|
|
@@ -583,12 +593,12 @@ import FlutterMacOS | |
| /// Writes decode and casting code for any type. | ||
| /// | ||
| /// Optional parameters are necessary for class decoding only. | ||
| void _writeDecodeCasting( | ||
| Root root, | ||
| Indent indent, | ||
| String value, | ||
| String variableName, | ||
| TypeDeclaration type, { | ||
| void _writeDecodeCasting({ | ||
| required Root root, | ||
| required Indent indent, | ||
| required String value, | ||
| required String variableName, | ||
| required TypeDeclaration type, | ||
| NamedType? field, | ||
| Set<String>? customClassNames, | ||
| Set<String>? customEnumNames, | ||
|
|
@@ -713,10 +723,15 @@ String _camelCase(String text) { | |
|
|
||
| String _castForceUnwrap(String value, TypeDeclaration type, Root root) { | ||
| if (isEnum(root, type)) { | ||
| assert(!type.isNullable); | ||
| return '${_swiftTypeForDartType(type)}(rawValue: $value as! Int)!'; | ||
|
||
| } else if (type.baseName == 'Object') { | ||
tarrinneal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Special-cased to avoid warnings about using 'as' with Any. | ||
| return value; | ||
| } else if (type.baseName == 'int') { | ||
| final String orString = | ||
| type.isNullable ? 'nilOrValue($value)' : '$value as! Int64'; | ||
| return '($value is Int32) ? Int64($value as! Int32) : $orString'; | ||
| } else if (type.isNullable) { | ||
| return 'nilOrValue($value)'; | ||
| } else { | ||
|
|
||
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.
It's more subtle than that; I'm pretty sure that passing
customClassNameswould actively break things (creating essentially the bug I fixed for C++ in #3573). I was actually confused at first about how the PR wasn't causing a regression there until I noticed that the call sites weren't passing the class list.If I'm correct about that, I think it would be better to make things much more explicit. E.g., you could rename
customClassNamestolistEncodedClassNames, and change this comment to explicitly say that a value for that must be provided only in the case of class decoding, with a link to flutter/flutter#119351 for context. (Alternately you could leave the name, but add an explicit bool like I did in the C++ generator.)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 renamed them. And made the comment more specific.