Skip to content

[SR-5497] Incorrect dynamic dispatch behaviour for class overridden across modules when using whole module optimization. #48069

@swift-ci

Description

@swift-ci
Previous ID SR-5497
Radar None
Original Reporter derekblr (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode Version 8.3.3 (8E3004b) , Swift 3

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

md5: 2d63037afdd34c62be4ebd4ea56801c8

duplicates:

  • SR-5499 Incorrect dynamic dispatch behaviour for nested class overridden across modules when using whole module optimization.

Issue Description:

Suppose in an external module we have these defs:

public struct Woof {
    open class Qux {
        open var name: String? {
            return nil
        }
        public func printName() {
            print(name ?? "no name")
        }
        public init() {}
    }
}

And then in the main module we have this:

class Foo: Woof.Qux {
    override var name: String {
        return "zorg"
    }    
}

let test = Foo()
test.printName()

Then if run with a release build config, we get "no name".
We can make it print "zorg" using any of the following changes:

Turn off "whole module optimization" for the external module.
Make Qux a non-nested type by moving it out of Woof.
Put all the code in the same module.

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