@@ -1186,8 +1186,28 @@ fn Generator(comptime WriterType: type) type {
1186
1186
return ;
1187
1187
}
1188
1188
1189
+ // Class 'type methods' and 'self methods' can have naming conflicts, e.g. NSCursor pop()
1190
+ // which takes a self parameter and NSCursor pop() which is a type method. We prefix the
1191
+ // type method one with 'T_' only if there would be a conflict.
1192
+ const nameConflict = blk : {
1193
+ var count : usize = 0 ;
1194
+ for (container .methods .items ) | m | {
1195
+ if (std .mem .eql (u8 , m .name , method .name )) count += 1 ;
1196
+ if (count >= 2 ) break :blk true ;
1197
+ }
1198
+ break :blk false ;
1199
+ };
1200
+ var name = method .name ;
1201
+ if (nameConflict and ! method .instance ) {
1202
+ const new_name = try self .allocator .alloc (u8 , method .name .len + 2 );
1203
+ @memcpy (new_name [2.. ], method .name );
1204
+ new_name [0 ] = 'T' ;
1205
+ new_name [1 ] = '_' ;
1206
+ name = new_name ;
1207
+ }
1208
+
1189
1209
try self .writer .writeAll (" pub fn " );
1190
- try self .generateMethodName (method . name );
1210
+ try self .generateMethodName (name );
1191
1211
try self .writer .print ("(" , .{});
1192
1212
try self .generateMethodParams (method );
1193
1213
try self .writer .print (") " , .{});
@@ -1935,6 +1955,7 @@ fn generateAppKit(generator: anytype) !void {
1935
1955
[2 ][]const u8 { "NSCursor" , "hide" },
1936
1956
[2 ][]const u8 { "NSCursor" , "unhide" },
1937
1957
[2 ][]const u8 { "NSCursor" , "pop" },
1958
+
1938
1959
[2 ][]const u8 { "NSCursor" , "push" },
1939
1960
[2 ][]const u8 { "NSCursor" , "arrowCursor" },
1940
1961
[2 ][]const u8 { "NSCursor" , "IBeamCursor" },
0 commit comments