Skip to content

[SR-6096] Runtime-Crash when constructing KeyPath #48651

@swift-ci

Description

@swift-ci
Previous ID SR-6096
Radar rdar://problem/34889333
Original Reporter tomquist (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
Target: x86_64-apple-macosx10.9
Xcode Version 9.0 (9A235)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, KeyPaths, RunTimeCrash
Assignee tomquist (JIRA)
Priority Medium

md5: 7e5bd566fa2f00a65d781a8dced48556

is duplicated by:

  • SR-6110 Runtime crash with nested optional key-path
  • SR-6281 Creating KeyPath with Optional Indexing Crashes
  • SR-6495 Segfault when using KeyPath on final class in struct with NSObject

relates to:

  • SR-6281 Creating KeyPath with Optional Indexing Crashes

Issue Description:

The following code produces a runtime crash:

protocol SomeProtocol {}
struct SomeType: SomeProtocol {}
struct Value<ValueType> {}
extension SomeProtocol {
    var asString: String? {
        return self as? String
    }
}
extension Value where ValueType: SomeProtocol {
    func doSomething() {
        print(\ValueType.asString?.endIndex)
    }
}
Value<SomeType>().doSomething()

Crash:

fatal error: UnsafeMutableRawBufferPointer with negative count
[1]    74901 illegal hardware instruction  ./test

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 softwarekey pathsFeature: key paths (both native and Objective-C)run-time crashBug → crash: Swift code crashed during execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions