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-4256] Chaining ‘dropFirst' Calls on Array is Ambiguous #46839

Closed
palimondo mannequin opened this issue Mar 15, 2017 · 4 comments
Closed

[SR-4256] Chaining ‘dropFirst' Calls on Array is Ambiguous #46839

palimondo mannequin opened this issue Mar 15, 2017 · 4 comments
Assignees
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

@palimondo
Copy link
Mannequin

palimondo mannequin commented Mar 15, 2017

Previous ID SR-4256
Radar rdar://problem/35625473
Original Reporter @palimondo
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler, Standard Library
Labels Bug, TypeChecker
Assignee @xedin
Priority Medium

md5: a89bf93bffd383ea145cfdd12007284b

Issue Description:

Straight out of Sequence.swift, from comment for optimization to avoid multiple wrappers when chaining dropFirst calls:

[1,2,3].dropFirst(1).dropFirst(1)

produces following error:

DropFirstChainOnArrayAmbiguous.swift:1:1: error: ambiguous use of 'dropFirst'
[1,2,3].dropFirst(1).dropFirst(1)
^
Swift.Collection:39:17: note: found this candidate
    public func dropFirst(_ n: Int) -> Self.SubSequence
                ^
Swift.Sequence:20:17: note: found this candidate
    public func dropFirst(_ n: Int) -> AnySequence<Self.Iterator.Element>
                ^

Workaround is to split the expression in two, storing first part in variable as seen in the tests for that method:

 let result0 = [1,2,3].dropFirst(1)
 let result1 = result0.dropFirst(1)

Given that we are just storing subexpressions in variables, without having to explicitly define types, this is a bug in compiler, which should be able to infer the most specific type - Collection in this case.

@belkadan
Copy link
Contributor

cc @rudkx

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Jun 12, 2017

Possible duplicate of SR-1856.

@xedin
Copy link
Member

xedin commented Nov 17, 2017

@swift-ci create

@xedin
Copy link
Member

xedin commented Nov 17, 2017

This is resolved by #12520 going to prefer SubSequence over AnySequence. @palimondo please verify and resolve.

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

No branches or pull requests

2 participants