Skip to content

[SR-10441] Demangler crash: Assertion failed: (false && "cannot add child") #52841

@theblixguy

Description

@theblixguy
Previous ID SR-10441
Radar None
Original Reporter @theblixguy
Type Bug
Environment

Swift 5.1 (near master), macOS 10.14.4

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

md5: fe28a105cf1569245add499d28117e10

Issue Description:

This code causes a crash in the demangler:

protocol Foo {
  associatedtype ErrorType: Error
}

extension Array: Error where Element: Error {}

class Bar<A: Foo> {
  func doSomething(with result: Result<Any, [A.ErrorType]>) {}
}
Assertion failed: (false && "cannot add child"), function addChild, file /Users/suyashsrijan/Documents/swift-src/swift/lib/Demangling/Demangler.cpp, line 355

Removing the where clause on the Array extension fixes the crash. The following code also leads to a crash, however it happens in the ASTMangler when calling `swift::Mangle::ASTMangler::getSpecialManglingContext()`:

extension Array: Error where Element: Error {}

class Bar {
  func doSomething(with result: Result<Any, [Error]>) {}
}
Assertion failed: (is<T>() && "Invalid accessor called"), function get, file /Users/suyashsrijan/Documents/swift-src/llvm/include/llvm/ADT/PointerUnion.h, line 136.

I think this has to do with passing an Array<Error> to the Result type and adding the constrained extension on Array.

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 software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions