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-10326] 'Self' is only available in a protocol or as the result of a method in a class; did you mean 'A'? #52726

Closed
DevAndArtist mannequin opened this issue Apr 6, 2019 · 9 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself properties Feature: properties Self in class Feature → types: The 'Self' type in classes type checker Area → compiler: Semantic analysis types Feature: types unexpected error Bug: Unexpected error

Comments

@DevAndArtist
Copy link
Mannequin

DevAndArtist mannequin commented Apr 6, 2019

Previous ID SR-10326
Radar None
Original Reporter @DevAndArtist
Type Bug
Status Resolved
Resolution Done
Environment

DEVELOPMENT-SNAPSHOT-2019-04-04-a

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

md5: 00af2a103a18af7ebe8084ad446ae844

Issue Description:

This is a strange limitation:

class A {
  // okay
  func _self() -> Self {
    return self
  }

  // error: 'Self' is only available in a protocol or as the result
  // of a method in a class; did you mean 'A'?
  var __self: Self {
    return self
  }
}
@belkadan
Copy link
Contributor

belkadan commented Apr 8, 2019

It's a workaround for #52537. :-/ @johnno1962, do you think it's worth tracking these separately, or should we just fold them together?

@johnno1962
Copy link
Contributor

This was fixed by #23485 I’ll close it now.

@johnno1962
Copy link
Contributor

This limitation is required and arises from an assert crashing the compiler when code generating the setter for the property of type Self

@belkadan
Copy link
Contributor

belkadan commented Apr 8, 2019

No, no. We want to support read-only properties with type Self.

@johnno1962
Copy link
Contributor

I’d like to @belkadan but I’ve struck an impasse, please see #23853 (comment)

@belkadan
Copy link
Contributor

belkadan commented Apr 9, 2019

My point is that it's fine if we can't implement it yet, but the bug shouldn't be closed until we can implement it.

@johnno1962
Copy link
Contributor

It would be nice to get it into 5.1 while we’re working on it. Any ideas on my conundrum?

@johnno1962
Copy link
Contributor

Non-mutable properties and subscripts allowed now: #23991

@slavapestov
Copy link
Member

This was implemented in #25742

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis Self in class Feature → types: The 'Self' type in classes unexpected error Bug: Unexpected error properties Feature: properties types Feature: types labels Nov 8, 2023
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 properties Feature: properties Self in class Feature → types: The 'Self' type in classes type checker Area → compiler: Semantic analysis types Feature: types unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants