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-1773] ..< is ambiguous together with map for certain closures #44382

Closed
swift-ci opened this issue Jun 15, 2016 · 2 comments
Closed

[SR-1773] ..< is ambiguous together with map for certain closures #44382

swift-ci opened this issue Jun 15, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

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

Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24).
OS X 10.11.5 (15F34)
Xcode 8.0 beta (8S128d)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 87c5a0a7f77c314a39495f411bd985df

duplicates:

  • SR-893 Compiler fails to infer return type of the transform closure in a map call

Issue Description:

When using ..< to generate the range to map over, the compiler can not resolve ..< when the closure is more complex.

The error is:

error: repl.swift:1:21: error: ambiguous reference to member '..<'
let result = (0 ..< 4).map {
^~~

Swift...<:14:13: note: found this candidate
public func ..<<Bound : Comparable>(minimum: Bound, maximum: Bound) -> Range<Bound>
^

Swift...<:14:13: note: found this candidate
public func ..<<Bound : _Strideable where Bound : Comparable, Bound.Stride : Integer>(minimum: Bound, maximum: Bound) -> CountableRange<Bound>

Code that works:

let result = (0 ..< 4).map {
$0
}

Code that doesn't work:

let result = (0 ..< 4).map {
let temp = $0
return temp
}

and

let result = (0 ..< 4).map { a in
let temp = a
return temp
}

@swift-ci
Copy link
Collaborator Author

Comment by Magnus Ahltorp (JIRA)

let range = 0..<4
let result = range.map { (a: Int) in
let temp = a
return temp
}

results in

error: repl.swift:2:20: error: expression type '[_]' is ambiguous without more context

while

let range = 0..<4
let result : [Int] = range.map { (a: Int) in
let temp = a
return temp
}

works.

@belkadan
Copy link
Contributor

There's some explanation linked in SR-1570.

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

No branches or pull requests

2 participants