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-461] prefix() chained after filter() confuses type inference when used on a sequence that uses AnyGenerator #43078

Closed
swift-ci opened this issue Jan 4, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself standard library Area: Standard library umbrella type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 4, 2016

Previous ID SR-461
Radar None
Original Reporter itchingpixels (JIRA User)
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 1
Component/s Compiler, Standard Library
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 7a921301033d688e26e6764735b18b41

duplicates:

  • SR-851 Result of dropFirst differs between 2.1.1 and 2.2

Issue Description:

When this code is typed in:

struct NaturalNumbers : SequenceType {
  internal func generate() -> AnyGenerator<Int> {
    var i = 0
    return anyGenerator {
      return i++
    }
  }
}


let standalonePrefix = (1...100).lazy.prefix(3)
print(Array(standalonePrefix))

let prefixWithFilter1: AnySequence<Int> = NaturalNumbers().lazy.filter { (number) -> Bool in
  return number % 2 == 0
  }.prefix(3)
print(Array(prefixWithFilter1))

let prefixWithFilter2 = NaturalNumbers().lazy.filter { (number) -> Bool in
  return number % 2 == 0
  }.prefix(3)
print(Array(prefixWithFilter2))

The compiler warns about "Ambiguous use of 'filter'" on the line where prefixWithFilter2 is defined.
I spent some time on trying to find the source problem, and this post helped me:
https://forums.developer.apple.com/thread/26147

I'm wondering if there's no way around the compiler making a choice of which type chain variation to go for, would it be possible to display a more detailed error message?
Unfortunately "Ambiguous use of 'filter'" didn't help me that much understanding the problem, and it also didn't suggest any resolution (which is actually quite easy).

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

Fixed by #12520

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

No branches or pull requests

2 participants