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-7920] Unexpected error when using generic subscript in protocol extension #50455

Closed
iby opened this issue Jun 7, 2018 · 5 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@iby
Copy link

iby commented Jun 7, 2018

Previous ID SR-7920
Radar rdar://problem/40971050
Original Reporter @iby
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @iby
Priority Medium

md5: 57b6ec815b38c3751be9caab99c587a1

Issue Description:

This works:

@belkadan
Copy link
Contributor

belkadan commented Jun 8, 2018

The error message is wrong, but the compiler is correct to reject the code: a subscript setter is implicitly mutating unless it's in a class or class-constrained protocol. (It's possible that the subscript setter implementation will reassign self, and therefore it can only be called on a var.)

@belkadan
Copy link
Contributor

belkadan commented Jun 8, 2018

cc @xedin

@iby
Copy link
Author

iby commented Jun 8, 2018

Ah, mutating… Spot on!

@xedin
Copy link
Member

xedin commented Jun 9, 2018

@swift-ci create

@hborla
Copy link
Member

hborla commented Feb 6, 2020

This is resolved in Swift 5.2. The compiler now reports:

error: cannot assign through subscript: 'c' is a 'let' constant
c[Foo<String>()] = "bar"
~^
note: change 'let' to 'var' to make it mutable
let c = MyClass()
^~~
var

Could you please verify using a recent 5.2 snapshot or the latest Xcode beta? Thank you!

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants