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-9628] For loop with optional output variable causes infinite loop #4612

Closed
swift-ci opened this issue Jan 9, 2019 · 1 comment
Closed
Labels
bug Something isn't working Compiler LLDB for Swift

Comments

@swift-ci
Copy link

swift-ci commented Jan 9, 2019

Previous ID SR-9628
Radar None
Original Reporter spamsencer (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

macOS 10.14.2 (18C54)

Xcode 10.1 (10B61)

Swift 4.2

iOS 12.1

Additional Detail from JIRA
Votes 0
Component/s Compiler, LLDB for Swift
Labels Bug
Assignee None
Priority Medium

md5: 7d00dc923db09215081ba8df4e706d89

duplicates:

Issue Description:

Creating a For Loop and designating the output variable type as an optional causes the loop to repeat infinitely, without warning, blocking whatever thread from which it is being executed. The following is an example of such a loop:

// Infinite Loop Example
let solarSystemArray = ["Mercury", "Venus", "Earth", "Mars"]
for planet: String? in solarSystemArray {
    print(planet? ?? "Unknown planet")
    // Repeats infinitely
}

// Normal Loop Example
let solarSystemArray = ["Mercury", "Venus", "Earth", "Mars"]
for planet: String in solarSystemArray {
 print(planet)
 // Executes as expected
}

This issue was particularly difficult to spot at first, as neither the compiler nor the run-time flagged this as an issue. At the very least, the Swift compiler should supply an infinite loop warning when this type of code is written.

@lorentey
Copy link
Member

This is the same issue as SR-8688.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 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 Something isn't working Compiler LLDB for Swift
Projects
None yet
Development

No branches or pull requests

2 participants