Description
Previous ID | SR-3864 |
Radar | None |
Original Reporter | C0deH4cker (JIRA User) |
Type | Bug |
Environment
Swift REPL from Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1), running on macOS 10.12.2 (16C67), MacBook Pro (Retina, 15-inch, Early 2013)
Additional Detail from JIRA
Votes | 0 |
Component/s | LLDB for Swift |
Labels | Bug, CompilerCrash |
Assignee | None |
Priority | Medium |
md5: c1831452b24ca25361772a01df03dce7
Issue Description:
In the Swift REPL, enter part 1 of the code below. After you see the error message about the undeclared type Bytes
, enter part 2. This will cause the REPL to crash. The two parts MUST be entered separately for the crash to occur, because otherwise the declaration for Bytes
will be visible the first time around. I believe this bug involves the type system. While minimizing the test case, I learned that the public
qualifier on the initializer is important, and also if the body is simply self = 0
the crash will not occur.
// Part 1
extension UInt {
public init(bytes: Bytes) {
self = 0
for byte in bytes {
self <<= 8
self |= UInt(byte)
}
}
}
// Part 2
public typealias Bytes = [UInt8]
extension UInt {
public init(bytes: Bytes) {
self = 0
for byte in bytes {
self <<= 8
self |= UInt(byte)
}
}
}
Here is a transcript of the REPL session:
$ swift
Welcome to Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1). Type :help for assistance.
1> // Part 1
2. extension UInt {
3. public init(bytes: Bytes) {
4. self = 0
5. for byte in bytes {
6. self <<= 8
7. self |= UInt(byte)
8. }
9. }
10. }
error: repl.swift:3:24: error: use of undeclared type 'Bytes'
public init(bytes: Bytes) {
^~~~~
1> // Part 2
2. public typealias Bytes = [UInt8]
3. extension UInt {
4. public init(bytes: Bytes) {
5. self = 0
6. for byte in bytes {
7. self <<= 8
8. self |= UInt(byte)
9. }
10. }
11. }
Segmentation fault: 11