77import 'dart:ffi' ;
88import 'dart:io' ;
99
10- import 'package:objective_c/objective_c.dart' ;
10+ import 'package:objective_c/objective_c.dart' as objc ;
1111import 'package:path/path.dart' as path;
1212import 'package:test/test.dart' ;
1313
@@ -87,14 +87,14 @@ void main() {
8787 'GoodbyeWorld!' ,
8888 );
8989
90- NSString str2 = str.instancetypeMethod ();
90+ objc. NSString str2 = str.instancetypeMethod ();
9191 expect (str2.toDartString (), 'Hello' );
9292 });
9393
9494 test ('Transitive category on built-in type' , () {
9595 // Regression test for https://github.com/dart-lang/native/issues/1820.
9696 // Include transitive category of explicitly included buit-in type.
97- expect (NSURL .alloc ().extensionMethod (), 555 );
97+ expect (objc. NSURL .alloc ().extensionMethod (), 555 );
9898
9999 // Don't include transitive category of built-in type that hasn't been
100100 // explicitly included.
@@ -111,5 +111,29 @@ void main() {
111111 // This method is from an NSObject extension, which shouldn't be included.
112112 expect (bindings, isNot (contains ('autoContentAccessingProxy' )));
113113 });
114+
115+ test ('Category that has the same name as an imported type that is the '
116+ 'supertype of another type in the same file' , () {
117+ // Regression test for https://github.com/dart-lang/native/issues/2762.
118+ final bindings = File (
119+ path.join (
120+ packagePathForTests,
121+ 'test' ,
122+ 'native_objc_test' ,
123+ 'category_bindings.dart' ,
124+ ),
125+ ).readAsStringSync ();
126+
127+ // Neither the NSString category, nor the NSString that's a supertype of
128+ // ChildOfNSString, have been renamed to NSString$1.
129+ expect (bindings, contains ('extension NSString on Thing {' ));
130+ expect (
131+ bindings,
132+ contains ('''
133+ extension type ChildOfNSString._(objc.ObjCObject object\$ )
134+ implements objc.ObjCObject, objc.NSString {
135+ ''' ),
136+ );
137+ });
114138 });
115139}
0 commit comments