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-11827] Missing "in" => bad diagnostic #2196

Open
dabrahams opened this issue Nov 21, 2019 · 3 comments
Open

[SR-11827] Missing "in" => bad diagnostic #2196

dabrahams opened this issue Nov 21, 2019 · 3 comments
Labels
SwiftParser Bugs in the (new) Parser written in Swift

Comments

@dabrahams
Copy link
Contributor

dabrahams commented Nov 21, 2019

Previous ID SR-11827
Radar rdar://problem/57418525
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 29d9832455f9840f7ae31e4c0ca0baec

Issue Description:

  1> (0..<10).map { x
  2.     x + 1
  3. }
error: repl.swift:1:10: error: cannot invoke 'map' with an argument list of type '(@escaping () -> ())'
(0..<10).map { x
         ^

repl.swift:1:10: note: expected an argument list of type '((Self.Element) throws -> T)'
(0..<10).map { x
         ^

I've also seen, "Contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored" (small reproducer harder to generate). Either way we should have an error saying "in" is missing and a fixit to insert it.

@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@xedin
Copy link
Contributor

xedin commented May 29, 2023

Looks like this has been fixed recently:

(0..<10).map { x
  x + 1
}
error: cannot find 'x' in scope
(0..<10).map { x
               ^
error: cannot find 'x' in scope
  x + 1
  ^
error: contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored
(0..<10).map { x
             ^
               _ in

Please verify using the most recent main branch toolchain from swift.org.

@AnthonyLatsis
Copy link
Contributor

AnthonyLatsis commented May 29, 2023

This sort of thing has come up before. I think we need a parser heuristic that would warn about argument-list-like syntax written on the same line as { when in cannot be found and the next token is on a different line. The obvious way to silence this warning would be to insert either the in keyword or a line break after {.

@ahoppen ahoppen removed the bug Something isn't working label Sep 14, 2023
@ahoppen ahoppen transferred this issue from swiftlang/swift Sep 14, 2023
@ahoppen ahoppen added the SwiftParser Bugs in the (new) Parser written in Swift label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftParser Bugs in the (new) Parser written in Swift
Projects
None yet
Development

No branches or pull requests

5 participants