Realm-js: Compile-time Error: control may reach end of non-void function with Xcode 10.2

Created on 26 Mar 2019  路  21Comments  路  Source: realm/realm-js

TL;DR

Thanks @AidenMontgomery.

  1. Open the source file at ${RN_PROJ}/node_modules/realm/src/jsc/jsc_value.hpp.
  2. Find the switch-case segment at THERE.
  3. Replace the whole switch-case segment with the following code.
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        case kJSTypeSymbol: return "symbol";
    }

Goals

When I were compiling the React Native Project with Xcode, the compiler prompts an error.

Expected Results

No error.

Actual Results

/Users/***/***/***/node_modules/realm/src/jsc/jsc_value.hpp:54:1: error: control may reach end of non-void function [-Werror,-Wreturn-type]

Version of Realm and Tooling

  • Realm JS SDK Version: 2.25.0
  • React Native: 0.58.6
  • Node: 10.15.2
  • Client OS & Version: iOS 12.2.0

Temp Solution

  1. Open the source code: ${RN_PROJ}/node_modules/realm/src/jsc/jsc_value.hpp;
  2. Add return "null"; between line 33 and 34.

I know this is not a good solution.
So I am looking forward to the official solution.

O-Community T-Bug

Most helpful comment

temp solution :

add default: return "null"; between line 52 and 53,

template<>
inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        default: return "null";
    }

}

this working for me, waiting for the official solution

All 21 comments

@Joyreece
similar problem, Today i upgrade system version to 10.14.4 and xcode version to 10.2,
After that, it will not work properly.This problem has been wasted my half-day time, The error message is as follows:

The following build commands failed:
    CompileC /Users/xxx/workspace/yqplus_app/ios/build/Build/Intermediates.noindex/RealmJS.build/Debug-iphonesimulator/RealmJS.build/Objects-normal/x86_64/jsc_value.o jsc/jsc_value.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler

your solution doesn't work for me.

temp solution :

add default: return "null"; between line 52 and 53,

template<>
inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        default: return "null";
    }

}

this working for me, waiting for the official solution

From what I can tell, and I'm probably wrong, there is a new entry in the JSType Enum kJSTypeSymbol which is not being handled in the switch statement.
Therefore the switch is not handling all of the possible values returned by JSValueGetType

I don't know what the effect of doing this will be, but I think that the solution is as follows...

inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        case kJSTypeSymbol: return "symbol";
    }
}

This does mean that when/if a new value is added to the Enum again we will see the same issue, unless there is a default added, I just don't know what that should do.

I have same isssue :(

From what I can tell, and I'm probably wrong, there is a new entry in the JSType Enum kJSTypeSymbol which is not being handled in the switch statement.
Therefore the switch is not handling all of the possible values returned by JSValueGetType

I don't know what the effect of doing this will be, but I think that the solution is as follows...

inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        case kJSTypeSymbol: return "symbol";
    }
}

This does mean that when/if a new value is added to the Enum again we will see the same issue, unless there is a default added, I just don't know what that should do.

makes sense

From what I can tell, and I'm probably wrong, there is a new entry in the JSType Enum kJSTypeSymbol which is not being handled in the switch statement.

Nope, I think you're correct @AidenMontgomery . This change was introduced in iOS 12.3 (see #2246), which was included in the Xcode update that was released today.

From what I can tell, and I'm probably wrong, there is a new entry in the JSType Enum kJSTypeSymbol which is not being handled in the switch statement.

Nope, I think you're correct @AidenMontgomery . This change was introduced in iOS 12.3 (see #2246), which was included in the Xcode update that was released today.

Same conclusion here.

Did someone make a Pull Request for this change ?

@StevenMasini yeah i made the Pull Request #2303 but no luck so far. also if anyone can check if PR is working with Xcode version below 10.2 would be great.

@mohammadalijf Ok let me check if that work on XCode 10.1.

@mohammadalijf

I succeed to compile on XCode 10.1 with the fix you made in #2303

Indeed kJSTypeSymbol isn't defined in JavaScriptCore in the iOS SDK 12.1.

#if defined __IPHONE_12_2 || defined __MAC_10_14_4
     case kJSTypeSymbol: return "symbol";
#endif

same problem

@StevenMasini thank you steven 馃憤

Thanks to this issue and 2221, 2282 issues we switched to SQLite which was a longtime dream of our team. It is clear that realm can't move fast enough to catch the ecosystem.

@sercand to be fair, the only way this would have been caught before the Xcode 10.2 public release is if someone noticed this in one of the Xcode 10.2 betas (I did notice this, and probably should have made a PR a long time ago). This was not documented in any SDK or Xcode release notes, at least from what I've seen. It was basically "out of the blue" since it was only added to the JavaScriptCore docs and no other documentation/release notes

when can we expect a new release guys?

@Joyreece I do not have realm in my node_modules! Any alternatives?

@Joyreece I do not have realm in my node_modules! Any alternatives?

Hi, bro.
You may have already installed it in the global environment.
Use the npm -g list | grep realm to check if it is in the global environment.

If it does, I still recommend that install into the project environment with following commands.

cd <PROJECT_PATH>
npm install --save realm

DO NOT miss the --save option~ :)

same issue for me

so, WHEN can we expect a new release guys?

@ValeriiKov this was fixed in v2.26.1

@kneth I think this issue can be closed

Was this page helpful?
0 / 5 - 0 ratings