Skip to content

Commit 29025e6

Browse files
committed
nit
1 parent 3e89893 commit 29025e6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pkgs/ffigen/lib/src/visitor/create_scopes.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ class CreateScopesVisitation extends Visitation {
8080
'noSuchMethod',
8181
};
8282

83-
void visitObjCMethods(ObjCMethods node, Scope localScope) {
83+
void visitObjCMethods(
84+
ObjCMethods node,
85+
ObjCInterface? superType,
86+
Scope classScope,
87+
) {
8488
for (final m in node.methods) {
85-
createScope(m, localScope, m.originalName);
89+
final parentScope =
90+
_findRootWithMethod(superType, m)?.localScope ?? classScope;
91+
createScope(m, parentScope, m.originalName);
8692
}
8793
}
8894

@@ -92,6 +98,7 @@ class CreateScopesVisitation extends Visitation {
9298
node.visitChildren(visitor, typeGraphOnly: orderedPass);
9399
visitObjCMethods(
94100
node,
101+
node.parent,
95102
createScope(
96103
node,
97104
node.parent.localScope,
@@ -111,6 +118,7 @@ class CreateScopesVisitation extends Visitation {
111118
}
112119
visitObjCMethods(
113120
node,
121+
node.superType,
114122
createScope(
115123
node,
116124
node.superType?.localScope ?? context.rootScope,
@@ -127,6 +135,7 @@ class CreateScopesVisitation extends Visitation {
127135
}
128136
visitObjCMethods(
129137
node,
138+
null,
130139
createScope(
131140
node,
132141
context.rootScope,
@@ -135,4 +144,14 @@ class CreateScopesVisitation extends Visitation {
135144
),
136145
);
137146
}
147+
148+
ObjCInterface? _findRootWithMethod(ObjCInterface? node, ObjCMethod method) {
149+
ObjCInterface? root;
150+
for (var t = node; t != null; t = t.superType) {
151+
if (t.getSimilarMethod(method) == null) break;
152+
root = t;
153+
}
154+
assert(root == null || root.getSimilarMethod(method) != null);
155+
return root;
156+
}
138157
}

0 commit comments

Comments
 (0)