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-598] String initialized with [Any] causes runtime crash #43215

Closed
jepers opened this issue Jan 22, 2016 · 4 comments
Closed

[SR-598] String initialized with [Any] causes runtime crash #43215

jepers opened this issue Jan 22, 2016 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself type checker Area → compiler: Semantic analysis

Comments

@jepers
Copy link

jepers commented Jan 22, 2016

Previous ID SR-598
Radar None
Original Reporter @jepers
Type Bug
Status Closed
Resolution Cannot Reproduce
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @jepers
Priority Medium

md5: 28a457a2eebf994c177f8f5e2ca4a7d3

Issue Description:

I have only tested this in swift-2.2-SNAPSHOT-2016-01-06-a-osx.pkg
(So maybe it's fixed in current master)

This program (cmd line prj, no imports) compiles fine but the resulting binary crashes at runtime:

let a: [Any] = [] // (Could as well be eg [1, "two"])
let s = String(a) // <-- Runtime crash here.
print(s)

Jumping to definition on the init of String.init(a) takes me here:

    /// Create an instance containing `characters`.
    public init<S : SequenceType where S.Generator.Element == Character>(_ characters: S)

which seems a bit strange (since the elements of a are not Characters).

@jepers
Copy link
Author

jepers commented Jan 22, 2016

@atrick
Copy link
Contributor

atrick commented Jan 22, 2016

I verified the crash on master.
This is crash is in String.init(Character)

As Jens pointed out, it's strange that we dispatch to String.init where Element == Character. At any rate, that attempts to initialize a String from a character with nil storage:

(Character) $R2 = {
_representation = Large {
Large = {
_storage = nil
}
}
}

I'm not sure why the code invokes the wrong String.init. It occurs at -Onone, with a debug stdlib and doesn't look like a runtime problem.

@jepers
Copy link
Author

jepers commented Jan 23, 2016

Possibly related to https://bugs.swift.org/browse/SR-550

@jepers
Copy link
Author

jepers commented Aug 4, 2016

Seems to have been fixed. Could not reproduce in dev snapshot 2016-08-04.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants