@@ -41,15 +41,30 @@ class ObjCBlock extends BindingType with HasLocalScope {
4141
4242 final usr = _getBlockUsr (returnType, renamedParams, returnsRetained);
4343
44+ final newBlockName = _getBlockName (
45+ returnType,
46+ renamedParams.map ((a) => a.type),
47+ reduced: false ,
48+ );
4449 final oldBlock = context.bindingsIndex.getSeenObjCBlock (usr);
4550 if (oldBlock != null ) {
51+ if (oldBlock.symbol.oldName != newBlockName) {
52+ // Block with matching signature, but a different name. This is usually
53+ // due to type aliases. Replace the name with the reduced name, so that
54+ // it makes sense as a name for all blocks sharing this signature.
55+ oldBlock.symbol.oldName = _getBlockName (
56+ returnType,
57+ renamedParams.map ((a) => a.type),
58+ reduced: true ,
59+ );
60+ }
4661 return oldBlock;
4762 }
4863
4964 final block = ObjCBlock ._(
5065 context,
5166 usr: usr,
52- name: _getBlockName (returnType, renamedParams. map ((a) => a.type)) ,
67+ name: newBlockName ,
5368 returnType: returnType,
5469 params: renamedParams,
5570 returnsRetained: returnsRetained,
@@ -96,11 +111,26 @@ class ObjCBlock extends BindingType with HasLocalScope {
96111 // type. These names will be pretty verbose and unweildy, but they're at least
97112 // sensible and stable. Users can always add their own typedef with a simpler
98113 // name if necessary.
99- static String _getBlockName (Type returnType, Iterable <Type > argTypes) =>
100- 'ObjCBlock_${[returnType , ...argTypes ].map (_typeName ).join ('_' )}' ;
101- static String _typeName (Type type) =>
102- type.toString ().replaceAll (_illegalNameChar, '' );
114+ static String _getBlockName (
115+ Type returnType,
116+ Iterable <Type > argTypes, {
117+ required bool reduced,
118+ }) {
119+ final types = [returnType, ...argTypes].map ((t) => _typeName (t, reduced));
120+ return 'ObjCBlock_${types .join ('_' )}' ;
121+ }
122+
123+ static String _typeName (Type type, bool reduced) =>
124+ (reduced ? _reducedType (type) : type).toString ().replaceAll (
125+ _illegalNameChar,
126+ '' ,
127+ );
103128 static final _illegalNameChar = RegExp (r'[^0-9a-zA-Z]' );
129+ static Type _reducedType (Type type) {
130+ if (type.baseType != type) return _reducedType (type.baseType);
131+ if (type.typealiasType != type) return _reducedType (type.typealiasType);
132+ return type;
133+ }
104134
105135 static String _getBlockUsr (
106136 Type returnType,
0 commit comments