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-14344] Problem passing from a static method a created instance of a subtype to a closure with Self-type parameter #56703

Open
swift-ci opened this issue Mar 12, 2021 · 1 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14344
Radar rdar://problem/75450772
Original Reporter forforester (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 9b7b59504609eef81f65b6cb2d22684a

Issue Description:

My idea is in a base class's static method to create an instance of a subtype and then pass it as a parameter of the created type to a provided closure:

class Foo {

{{ required init() {}}}

{{ class func createSubtype(initialize: (Self) -> Void) -> Self {}}

{{ let new = Self()}}

{{ initialize(new)}}

{{ return new}}

{{}}}

class Bar: Foo {

{{ var v: Int?}}

}

let bar = Bar.createSubtype() { new in

{{ new.v = 1}}

{{}}}

Doing that the Swift compiler yields an error Value of type 'Self' has no member 'v'. But 'print(type(of: o))' in the closure gives 'Bar'. According to [Expanding Swift Self to class members and value types|https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md] implemented in Swift 5.1 using 'Self' should be appropriate here.

@typesanitizer
Copy link

@swift-ci create

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

No branches or pull requests

2 participants