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-7774] Better Error Message for Closures Capturing Self #50313

Open
swift-ci opened this issue May 25, 2018 · 0 comments
Open

[SR-7774] Better Error Message for Closures Capturing Self #50313

swift-ci opened this issue May 25, 2018 · 0 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7774
Radar None
Original Reporter charlieMonroe (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: bda41c07b5f860532f28f58efa76df5b

relates to:

  • SR-13637 Poor error message for closure capture list without in

Issue Description:

Here are two small examples:

class XUEntityProperty<EntityType>: NSObject {
}

class XUPrimitiveValueProperty<EntityType: NSObject, ValueType>: XUEntityProperty<EntityType> {
}

class XUArrayProperty<EntityType: NSObject, ItemType: NSObject>: XUPrimitiveValueProperty<EntityType, Array<ItemType>> {

        // Error: 'unowned' may only be applied to class and class-bound protocol
        // types, not '(XUArrayProperty<EntityType, ItemType>) -> () -> 
        // XUArrayProperty<EntityType, ItemType>'
    var validator: ((EntityType, ItemType) -> Bool) = { [unowned self] (_, _) -> Bool in
        return true
    }
    
}
class Foo {
        // Error: Use of unresolved identifier 'self'
    var validator: () -> Bool = { [unowned self] in
        return true
    }
}

In both cases the issue is referencing self - using lazy for the var field fixes the issue, but the error messages are nonetheless a bit confusing, mainly the first one, claiming that unowned may be only be used with classes and class-bound protocols...

@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
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

1 participant