Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9137] A runtime crash #3598

Closed
swift-ci opened this issue Oct 30, 2018 · 4 comments
Closed

[SR-9137] A runtime crash #3598

swift-ci opened this issue Oct 30, 2018 · 4 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-9137
Radar None
Original Reporter linqingmo (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift Development Snapshot 2018-10-24(a)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Codable, RunTimeCrash
Assignee None
Priority Medium

md5: ba85cac67076db675d6cae11ecfceb9c

Issue Description:

protocol _Decodable: Decodable {}

extension _Decodable {
    static func decode(from data: Data) throws -> Self {
        let decoder = JSONDecoder()
        return try decoder.decode(self, from: data)
    }
}

private class _JSONDecoder1: _JSONDecoder {
}


extension JSONDecoder {
    func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: _Decodable {
        let topLevel = try JSONSerialization.jsonObject(with: data, options: [JSONSerialization.ReadingOptions(rawValue: 1 << 15)])
        let decoder = _JSONDecoder1( // _JSONDecoder dose not crash
            referencing: topLevel,
            options: JSONDecodingOptions(
                dateDecodingStrategy: dateDecodingStrategy,
                dataDecodingStrategy: dataDecodingStrategy,
                nonConformingFloatDecodingStrategy: nonConformingFloatDecodingStrategy,
                keyDecodingStrategy: keyDecodingStrategy,
                userInfo: userInfo
            )
        )
        return try T(from: decoder)
    }
}

This code will cause a runtime crash, and the error message is useless.

@belkadan
Copy link

cc @itaiferber

@itaiferber
Copy link
Contributor

This doesn't appear to be a Codable issue but a crash in the type metadata accessor for a private type defined by the project (the project copies JSONEncoder.swift with some additions). This appears to boil down to the equivalent of:

private class Foo { ... }
private class Bar : Foo { /* no overrides */ }

Foo.init(...) // works fine
Bar.init(...) // crashes upon stepping in

FWIW, I don't see this issue on master, so it appears to have been resolved by something. I can't seem to get the actual trace to print out so here's a screenshot of the stack trace I guess:

@belkadan Does this look familiar at all?

@belkadan
Copy link

Oh, since last week? Maybe. @DougGregor, is this the thing you fixed?

@DougGregor
Copy link
Member

This was fixed by referencing private types symbolically in mangled names within metadata, apple/swift#20011.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants