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-11277] Incorrect fix-it for property wrapper #53678

Open
Agarunov opened this issue Aug 9, 2019 · 4 comments
Open

[SR-11277] Incorrect fix-it for property wrapper #53678

Agarunov opened this issue Aug 9, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers

Comments

@Agarunov
Copy link

Agarunov commented Aug 9, 2019

Previous ID SR-11277
Radar None
Original Reporter @Agarunov
Type Bug
Environment

Swift 5.1 25.07.2019

Master 06.08.2019

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

md5: 78089d8ad73de168d37631a50f8c728a

Issue Description:

This code provides incorrect fix-it:

class Value {
    @A(other: 0) var some: Int = 100 // error
    // Incorrect argument label in call (have 'wrappedValue:other:', expected 'initialValue:other:')
    // Replace '100' with 'initialValue'
}

@propertyWrapper
struct A<T> {
    var wrappedValue: T
    let other: T

    init(initialValue: T, other: T) {
        self.wrappedValue = initialValue
        self.other = other
    }
}

If I apply fix-it:

class Value {
    @A(other: 0) var some: Int = initialValue // error: Use of unresolved identifier 'initialValue'
}

If I change initialValue in init to wrappedValue everything compile correctly

@theblixguy
Copy link
Collaborator

The problem here is we have an implicit tuple expression (wrappedValue,other). wrappedValue comes from the assigned value which is why I think it seems to be pointing the fix-it to the value. There's a few ways to fix this:

1. Emit fix-its to insert `initialValue: 100` before `other`
2. Emit fix-it to replace `initialValue` with `wrappedValue` in the wrapper (not sure how this will work if its in a different file, etc).
3. Change the diagnostic text and remove the fix-it (similar to solution for SR-11060)

What do you think @xedin? Do you have any other ideas?

@xedin
Copy link
Member

xedin commented Aug 28, 2019

@theblixguy I think from usability standpoint #1 makes most sense, fix-it should form `@A(initialValue: 100, other: 0) var some: Int`

@theblixguy
Copy link
Collaborator

@xedin Sounds good! Although I don't have access to the variable inside diagnoseArgumentLabelError(). That is required to remove the '= 100' part. In LabelingFailure, we only have access to the CallExpr, but not the PatternBindingDecl.

@xedin
Copy link
Member

xedin commented Sep 18, 2019

Me and @DougGregor talked about this yesterday. It seems that the best option to solve this would be to actually start type-checking patterns via constraint solver.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

3 participants