Skip to content

[SR-6004] Static libraries don't automatically load extensions #48561

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-6004
Radar rdar://problem/34686622
Original Reporter soffes (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.0 (9A235)

Additional Detail from JIRA
Votes 7
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: a88822ddd333e2719ad59655283f788c

is duplicated by:

  • SR-10507 Dynamic cast to existential fails when conformance is added in extension in static library

Issue Description:

I'm not sure if this is the intended behavior, but a static library doesn't load extensions unless something else in the same file is explicitly referenced. I realize adding `all_load` to the target it is linked into solves this. I'd love to avoid that if possible.

This is more of a question of is this the indeed behavior and if so is doing `all_load` the intended use?

I've attached a sample project reproducing this. Here's an explanation:

  1. Create a static library A containing a protocol and some types that conform to it

  2. Create another static library B that creates some another protocol and adds extensions to types in static library A

  3. In another target that links both A & B, you can observe types from A that conform to a protocol from B not doing so at runtime.

  4. If you explicitly reference something in a file that adds conformation, it will load the extension with the conformance and work as expected.

The attached sample project may make this more clear. Start in ViewController.swift and check out the comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions