dropbox / djinni

A tool for generating cross-language type declarations and interface bindings.
Apache License 2.0
2.88k stars 488 forks source link

Add cast to objective C convenience initializers to prevent naming co… #413

Closed wpurdy2 closed 5 years ago

wpurdy2 commented 5 years ago

In generated Objective C code, convenience initializers can easily cause naming collisions with built in ios functions and other code that follows the same naming pattern. As a trivial example, consider the following record:

MyColor = record { red : f32; green : f32; blue : f32; alpha : f32; } deriving( eq )

This produces a function that looks something like this: (nonnull instancetype)MyColorWithRed:(float)red { (nonnull instancetype)MyColor:(float)red green:(float)green blue:(float)blue alpha:(float)alpha { return [[self alloc] initWithRed:red green:green blue:blue alpha:alpha]; } }

If your project happens to include UIKit, this generated code will emit a compilation error because InitWithRed is defined in UIKit (see https://developer.apple.com/documentation/uikit/uicolor/1621925-initwithred?language=objc) and without qualification, the call is ambiguous.

Adding a cast to the generated code disambiguates the call to initWithRed (and other similar situations)

xianwen commented 5 years ago

Hi, @wpurdy2: I noticed you haven't signed the CLA yet, could you please sign it here: https://opensource.dropbox.com/cla/ Thanks a lot!