Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Swift: an unqualified call to an inherited or extension member resolves to an unrelated top-level function

Closed
#909 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
swift, typescript
Domain
devtools

Research direction

Start in src/wiki-engine/code-knowledge/ast/call-resolver.ts at the bare-call fallback around line 113 and the receiver fallback around line 161; read how findSwiftModuleSymbol and localBindings are used. Reproduce the inherited and extension-member fixtures described in the issue, comparing the ast/walk.ts revisions mentioned for #847. Done means Swift fallback resolution no longer emits unrelated REFERENCES edges for inherited or extension members, including the receiver case.

Written by the indexing model from the issue text.

Description

An unqualified call inside a type is resolved against the module's top-level declarations when the
current file does not bind the name. That is wrong when the name is a member the type already has —
inherited from a superclass, or added by an extension: Swift resolves the call to that member, while the
fallback emits a REFERENCES edge to an unrelated top-level function.

1. Minimal reproduction

// Sources/App/Base.swift
class Base {
  func work() -> Int { return 1 }
}

// Sources/App/Sub.swift
class Sub: Base {
  func run() -> Int { return work() }
}

// Sources/App/Global.swift
func work() -> Int { return 2 }

Expected: no edge (or one to Base.swift, which the index does not model as a member).
Actual: Sub.swift -REFERENCES-> Global.swift, confidence INFERRED.

An extension declared in a third file behaves the same:

// Sources/App/Ext.swift
extension Sub {
  func work() -> Int { return 3 }
}

2. Where it comes from

src/wiki-engine/code-knowledge/ast/call-resolver.ts:113 — the bare-call fallback — consults
findSwiftModuleSymbol, which only knows declarations the module index collected as top-level and
module-visible. Members are in neither set, so the top-level func work() is the only candidate and it wins.

The localBindings guard on the same line does not help: it suppresses names bound inside the calling
file
, and a member declared in another file (or inherited) is not bound there.

3. Scope

Swift only, and only for unqualified calls the same-file and import lookups leave unresolved. Both the
callee fallback (:113) and the receiver fallback (:161) have the shape — a subclass method shadowing
a module-level class name behaves the same way.

4. Candidate directions

Resolving it needs information the AST index does not build today: declared supertypes per type, the set
of extensions per type, and member names per type. Directions worth weighing:

  • index members per type, and carry the enclosing type's inherited/extension members onto the call site so
    the existing localBindings guard can cover them;
  • or restrict the bare-call fallback to names no type in the module declares as a member — cheaper, and in
    the same "rather miss an edge than invent one" direction.

5. Relation to #847

Not introduced by #847. The graph is identical with and without that change: running this fixture against
both revisions of ast/walk.ts emits one REFERENCES edge either way. It is split out here because
#847's review pass surfaced it and it is out of scope there — that change replaces the local-shadowing
rule, whereas this is a missing piece of the module model rather than a defect in the rule.

Dominant language
TypeScript
Stars
5.1k
Forks
386
Avg merge
19h 44m
Merged PRs (30d)
320

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Tencent/teamai-cli

All issues in Tencent/teamai-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.