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-3864] Interpreter crashes when undeclared typealias is used (and errors), declared, then used again #4641

Open
swift-ci opened this issue Feb 5, 2017 · 1 comment
Labels

Comments

@swift-ci
Copy link

swift-ci commented Feb 5, 2017

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
@CodaFi
Copy link
Member

CodaFi commented Jun 8, 2017

This does not reproduce on master or on the Swift shipping with Xcode 9.0

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

No branches or pull requests

2 participants