Skip to content

BridgeJS: Resolve qualified types relative to lexical scope - #806

Merged
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:fix/relative-qualified-types
Aug 17, 2026
Merged

BridgeJS: Resolve qualified types relative to lexical scope#806
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:fix/relative-qualified-types

Conversation

@krodak

@krodak krodak commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

BridgeJS passed qualified type references directly to root lookup. Unlike unqualified identifiers, paths such as Shelf.Divider never searched the enclosing lexical scope, so valid APIs in extensions were diagnosed as unsupported and omitted from the generated bindings.

This applies the existing innermost-to-outermost lookup to the complete qualified path. Extension declarations still resolve their own target from the root scope, while references inside the extension body use the extension's lexical scope.

Closes #805.

Problematic case

@JS class Library {
    @JS struct Shelf {
        @JS struct Divider {
            @JS init() {}
        }
    }
}

extension Library {
    @JS func divider(_ value: Shelf.Divider) -> Shelf.Divider {
        value
    }
}

Before, both appearances of Shelf.Divider produced Unsupported type 'Shelf.Divider'. After, the method is exported with the Swift-resolved path:

export interface Library {
    divider(value: Library.Shelf.Divider): Library.Shelf.Divider;
}

Fix

  • Apply lexical lookup to both IdentifierTypeSyntax and MemberTypeSyntax
  • Keep extension targets root-qualified so an extension cannot resolve into its own member scope
  • Cover relative paths and the extension-target shadowing case in codegen and linker snapshots

Test plan

  • BridgeJS plugin tests and snapshots with swift-syntax 600, 601, 602, and 603
  • Generated TypeScript declaration validation
  • AoT binding regeneration

@krodak krodak self-assigned this Aug 17, 2026
@krodak
krodak requested a review from kateinoigakukun August 17, 2026 12:11
@krodak
krodak merged commit 8f4c851 into swiftwasm:main Aug 17, 2026
16 checks passed
@krodak
krodak deleted the fix/relative-qualified-types branch August 17, 2026 21:45
@wfltaylor

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BridgeJS: Resolve qualified type references relative to extension scope

3 participants