Open swift-ci opened 4 years ago
Comment by Thomas (JIRA)
Quick look into standard library showed that initialization from string is handled this way.
@inlinable @inline(__always)
public init(_ s: String) {
_precondition(!s.isEmpty,
"Can't form a Character from an empty String")
_debugPrecondition(s.index(after: s.startIndex) == s.endIndex,
"Can't form a Character from a String containing more than one extended grapheme cluster")
if _fastPath(s._guts._object.isPreferredRepresentation) {
self.init(unchecked: s)
return
}
self.init(unchecked: String._copying(s))
}
I assume it was done to achieve higher performance. That could be more appropriately modeled as failable init. However performance is the goal here.
@swift-ci create
Environment
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5) Target: x86_64-apple-darwin18.7.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 9b87db2713846f0076a6ed9143cc84a3Issue Description:
Attempting to create a Character variable with an empty string crashes the Swift compiler.
Steps to reproduce:
Enter the following code into the Swift REPL
Expected Results:
A diagnostic with the error 'Can't form a Character from an empty String', and compiler doesn't crash.
Actual Results: