Skip to content
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

PromiseKit crashes when promise is nil #344

Closed
toddrick opened this issue Dec 23, 2015 · 1 comment
Closed

PromiseKit crashes when promise is nil #344

toddrick opened this issue Dec 23, 2015 · 1 comment

Comments

@toddrick
Copy link

This is not how it should behave in objc.

AnyPromise *promise = nil;
promise.then(^{
NSLog(@"Hello World");
});

This will crash in objective c. However, the objective-c paradigm is that calling a method on a nil object should send a message to a nil object which is refused, thereby not executing. Therefore my expectation is that in this case we would not log "hello world."

However, PromiseKit crashes in this situation. I think this stems from the _nonnull qualifier on then, catch, and finally, but I'm not sure.

@mxcl
Copy link
Owner

mxcl commented Dec 24, 2015

The crash is because you are calling the then block:

promise.then(^{
    //
});

If you just did [promise then]; or promise.then; it would not crash.

Calling a nil block crashes:

void (^block)() = nil;
block();  //CRASH!

This cannot be fixed. It is because of the dot-notated syntax, and is unfortunate. This is documented at http://promisekit.org.

@mxcl mxcl closed this as completed Dec 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants