Skip to content

[iOS] Inconsistent behaviour when converting homogeneous arrays as native call arguments #25339

@gavrix

Description

@gavrix

On iOS, when calling native method that accepts array as argument, automatic conversion of values inside array is different in Release and Debug configuration. What works in Debug crashes in Release

React Native version:
React Native Environment Info:
System:
OS: macOS 10.14.5
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 663.40 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
Yarn: 1.13.0 - ~/.dev/yarn/1.13.0/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.11.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.8 => 0.59.8

Steps To Reproduce

Call AsyncStorage.set('key', 123)
Above works in Debug and crashes in Release

Describe what you expected to happen:

Above works in debug as number (although types suggest it explicitly expects string) gets automatically converted to string via sequence of calls ending with RCTConvertArrayValue which converts converts anything to expected type (which is NSString)

NSArray *RCTConvertArrayValue(SEL type, id json)

in Release sequence of macro calls is different though, never reaching RCTConvertArrayValue as can be seen here

#if RCT_DEBUG
#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) RCT_ARRAY_CONVERTER_NAMED(type, name)
#else
#define RCT_JSON_ARRAY_CONVERTER_NAMED(type, name) + (NSArray *)name##Array:(id)json { return json; }
#endif
#define RCT_JSON_ARRAY_CONVERTER(type) RCT_JSON_ARRAY_CONVERTER_NAMED(type, type)

What I think is expected behaviour is that in Debug it should log error descriptions of types mismatches but never convert anything to NSString automatically.

Were there any considerations as to why automatic conversion to string was added that I am missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPlatform: iOSiOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions