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-5876] Swift 4 no longer infers inout parameters #48446

Closed
lilyball mannequin opened this issue Sep 12, 2017 · 3 comments
Closed

[SR-5876] Swift 4 no longer infers inout parameters #48446

lilyball mannequin opened this issue Sep 12, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0 type checker Area → compiler: Semantic analysis

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Sep 12, 2017

Previous ID SR-5876
Radar None
Original Reporter @lilyball
Type Bug
Status Closed
Resolution Done
Environment

Xcode 9.0 (9A235)

Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
Target: x86_64-apple-macosx10.9

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

md5: eede21d4c9a5d30d1daac160c51a12fd

Issue Description:

Swift 3.1 infers inout parameters correctly. For example:

let seq = sequence(state: 1 as Int, next: { (counter) -> Int? in
    defer { counter += 1 }
    return counter == 10 ? nil : counter
})
print(seq.reduce(0, +))

This correctly compiles and prints 45. But Swift 4 complains instead with the error

unnamed.swift:2:21: error: left side of mutating operator isn't mutable: 'counter' is a 'let' constant
    defer { counter += 1 }
            ~~~~~~~ ^
@belkadan
Copy link
Contributor

@xedin, is this what you were just looking at recently?

@xedin
Copy link
Member

xedin commented Sep 13, 2017

Thanks, @belkadan! Yes, this has been fixed by #11855 which prevents invalid contractions of subtype constraints.

Eridius (JIRA User) please use the latest nightly build of the compiler to verify.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Sep 14, 2017

Verified, the latest nightly compiles this code correctly.

@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 regression swift 4.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants