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-4279] Eager prefix(while:) on sequence(...).lazy instance #46862

Closed
palimondo mannequin opened this issue Mar 17, 2017 · 3 comments
Closed

[SR-4279] Eager prefix(while:) on sequence(...).lazy instance #46862

palimondo mannequin opened this issue Mar 17, 2017 · 3 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

@palimondo
Copy link
Mannequin

palimondo mannequin commented Mar 17, 2017

Previous ID SR-4279
Radar rdar://problem/31194055
Original Reporter @palimondo
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode Version 8.3 beta 4 (8W143q)

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

md5: 07b8a4858b3678887ebe1acf699ebb5b

relates to:

  • SR-1856 prefix() chained after sorted() and before map() confuses type inference in 3.0

Issue Description:

Executing following test case never terminates:

extension Sequence {
    func _length() -> Int {
        return reduce(0, {$0.0 + 1})
    }
}

func lengthOfBoundedInfiniteSequence() -> Int {
    return sequence(first: 0, next: {$0}).lazy.prefix(while: {$0 < 2}).prefix(16)._length()
}

lengthOfBoundedInfiniteSequence()

If you start splitting the chain of sequence operations to 1 and 2 subexpressions, compiler gives error: ambiguous use of 'prefix(while: )’.

func lengthOfBoundedInfiniteSequence1() -> Int {
    let a = sequence(first: 0, next: {$0})
    return a.lazy.prefix(while: {$0 < 2}).prefix(16)._length()
}
lengthOfBoundedInfiniteSequence1()

func lengthOfBoundedInfiniteSequence2() -> Int {
    let a = sequence(first: 0, next: {$0})
    let b = a.lazy
    return b.prefix(while: {$0 < 2}).prefix(16)._length()
}
lengthOfBoundedInfiniteSequence2()

When you split it to 3 subexpressions, all of them type inferred, suddenly all works as it should:

func lengthOfBoundedInfiniteSequence3() -> Int {
    let a = sequence(first: 0, next: {$0})
    let b = a.lazy
    let c = b.prefix(while: {$0 < 2})
    return c.prefix(16)._length()
}
lengthOfBoundedInfiniteSequence3() // returns 16

This looks like it’s related to SR-4256? (cc @rudkx)

Note: You can ignore the attached main.swift - that was before I minimized the test case.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Mar 17, 2017

This splitting also works correctly:

func lengthOfBoundedInfiniteSequence4() -> Int {
    let a = sequence(first: 0, next: {$0}).lazy.prefix(while: {$0 < 2})
    return a.prefix(16)._length()
}
lengthOfBoundedInfiniteSequence4()

@airspeedswift
Copy link
Member

@swift-ci create

@xedin
Copy link
Member

xedin commented Nov 18, 2017

@palimondo I think this has been fixed on master but signature of some stdlib functions has changed, can you please verify using nightly and resolve if everything is ok, otherwise please assign to me!

@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

2 participants