fix: method argument name collision
Sometimes, the generated argument name for methods collide with reserved words. This patch simplifies the name of method arguments to prevent these collisions.
- Before:
@interface AMSBagUnderlyingDataPersistence
- (id)underlyingDataFor:(id)for error:(id *)_error;
- After:
@interface AMSBagUnderlyingDataPersistence
- (id)underlyingDataFor:(id)arg0 error:(id *)arg1;
That's the way I used to have it, but much preferred the auto completion with best guess names.
It might be impossible to achieve but would it be possible to check generated names vs keyword list then prepend arg if it is a keyword?
I'm willing to concede if there are too many edge cases etc
I think is not hard to create a table of reversed words and prepend something to the identifier. The only possible problem that comes to my mind is if we have a typedef’d name that collides with the argument name. But not 100% sure that is a problem, maybe the compiler allows it.
Ideally, I would like to implement this: https://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#objective-c-methods
It explains with a lot of detail how Swift picks argument names for Objective-C methods.
But it would require an amount of time that I don’t think it’s worth spending right now.
Done, added a list of C and C++ reserved words. If an argument name matches a keyword, an underscore is prepended to the identifier.
It seems there are no true reserved words in Objective-C, clang was able to compile methods with arguments named BOOL, Class, SEL, and id.
Ideally, I would like to implement this: https://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#objective-c-methods
It explains with a lot of detail how Swift picks argument names for Objective-C methods.
But it would require an amount of time that I don’t think it’s worth spending right now.
This would be great and what my lazy implementation was trying to mimic