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-12398] Poor pattern matching diagnostic: "for-in loop requires '[Int]' to conform to 'Sequence'" #54836

Closed
dan-zheng opened this issue Mar 23, 2020 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@dan-zheng
Copy link
Collaborator

Previous ID SR-12398
Radar rdar://problem/60832876
Original Reporter @dan-zheng
Type Bug
Status Resolved
Resolution Done
Environment
Apple Swift version 5.2 (swiftlang-1103.0.22 clang-1103.0.22)
Target: x86_64-apple-darwin19.3.0 
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @dan-zheng
Priority Medium

md5: 4541d0d7faeeac2d0db314717dd18ef8

Issue Description:

Reproducer:

let xs = [1, 2, 3]
let ys = [1, 2, 3]
for (x, y) in xs {}
$ swift diag.swift
diag.swift:3:15: error: for-in loop requires '[Int]' to conform to 'Sequence'
for (x, y) in xs {
              ^~

The error message doesn't make sense because [Int] does conform to Sequence.

I would expect a pattern-matching error message along the lines of:

$ swift diag.swift
diag.swift:3:5: error: tuple pattern cannot match values of the non-tuple type '[Int].Element' (aka 'Int')
for (x, y) in xs {
        ^~

Context: the intended code uses zip(xs, ys) instead of xs:

let xs = [1, 2, 3]
let ys = [1, 2, 3]
for (x, y) in zip(xs, ys) {}
@beccadax
Copy link
Contributor

@swift-ci create

@xedin
Copy link
Member

xedin commented Mar 31, 2020

Fixed by #30728 Please use next available master snapshot to verify and close.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants