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-8688] Infinite loop of for-in #51201

Closed
swift-ci opened this issue Sep 4, 2018 · 3 comments
Closed

[SR-8688] Infinite loop of for-in #51201

swift-ci opened this issue Sep 4, 2018 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 4, 2018

Previous ID SR-8688
Radar rdar://problem/47162940
Original Reporter mshibanami (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode Version 9.4.1 (9F2000)

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0

(Also confirmed on 4.2-DEVELOPMENT-SNAPSHOT-2018-07-28-a at http://online.swiftplayground.run/)

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee @typesanitizer
Priority Medium

md5: b2651170671df216008cba141bb6580f

is duplicated by:

  • SR-9628 For loop with optional output variable causes infinite loop
  • SR-9917 Infinite for-in loop

relates to:

  • SR-3023 Infinite loop iterating through Array of IUOs
  • SR-8326 Surprising interaction between casting to Any and optional promotion

Issue Description:

This simple for-in clause causes an infinite loop:

var array = ["hi"]
for text: String? in array {
    print("hello")
}

It'll be resolved if you change String? to String.

See also the attached GIF.

However, I'm not really sure this is a bug or an expected behaviour.

@belkadan
Copy link
Contributor

belkadan commented Sep 4, 2018

Interesting. @rudkx, this is related to your post about if-let on the forums, https://forums.swift.org/t/inconsistent-optional-injection-behavior/14628.

@typesanitizer
Copy link

PR with fix: #34979

@typesanitizer
Copy link

Landed fix on release/5.4 branch: #35386

@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 in itself
Projects
None yet
Development

No branches or pull requests

3 participants