Skip to content

[SR-4611] Runtime crash with nested type used as superclass generic argument #47188

@swift-ci

Description

@swift-ci
Previous ID SR-4611
Radar None
Original Reporter mlwoollard (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash, Runtime
Assignee None
Priority Medium

md5: cae105004f0afe8b0cad98e9ecd852b9

duplicates:

  • SR-5650 Remove parent field from type metadata

relates to:

  • SR-3779 Program with struct nested in generic struct crashes because of “cyclic metadata dependency”
  • SR-5432 Using nested type as a superclass generic parameter leads to a crash

Issue Description:

The following code compiles without warning but when run crashes instantiating Subclass instance, prior to entering Subclass.init. Would appear to be due to having nested struct A defined within Subclass and this being used as generic parameter. Refactoring struct A so its not nested and no crash. If this is not valid to use nested type as generic parameter like this should not the compiler give an error? If it is valid code the runtime crash should be fixed.

$ swiftc --version
Apple Swift version 3.1 (swiftlang-802.0.51 clang-802.0.41)

class Base<T> {}

class Subclass: Base<Subclass.A> {
    
    struct A {}
    
    override init() {
        super.init()
    }    
}

let _ = Subclass()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during executionruntimeThe Swift Runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions