Skip to content

String equality is broken #4

Description

@zeen

All strings are separate copies, so '==' checks break.

e.g.,

private function test() {
    var x = "hello";
    var t = (x == "hello");
    return t ? "Good" : "Bad";
}

generates this Objective-C:

- (NSMutableString*) test{
    NSMutableString *x = [@"hello" mutableCopy];
    BOOL t = x == [@"hello" mutableCopy];
    return ( (t) ? [@"Good" mutableCopy] : [@"Bad" mutableCopy]);
}

i.e., it returns Bad, because both instances of "hello" are separate copies, and '==' is false.

The fix for this would either be string interning, or using NSString.isEqualToString.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions