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-11457] Incorrect diagnostic when assigning incorrect type through keypath #53858

Closed
rnapier opened this issue Sep 11, 2019 · 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 key paths Feature: key paths (both native and Objective-C)

Comments

@rnapier
Copy link

rnapier commented Sep 11, 2019

Previous ID SR-11457
Radar rdar://problem/55594000
Original Reporter @rnapier
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11GM

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, KeyPaths
Assignee @rnapier
Priority Medium

md5: af9fa220b8670a12e92a4c0e6c0271b7

Issue Description:

When assigning through a WritableKeyPath, if the assigned value is of the wrong type, the error will be "Cannot assign through subscript, ... is immutable" rather than something pointing to the value of the type. For example:

struct Stuff { var a: String = "" }
var stuff = Stuff()
let kp: WritableKeyPath<Stuff, String> = \Stuff.a
stuff[keyPath: kp] = "abc".prefix(1)  // Cannot assign through subscript: 'stuff' is immutable

Note that "abc".prefix(1) is a Substring rather than a String, a subtle point that makes this a particularly confusing error.

@belkadan
Copy link
Contributor

cc @hborla, @xedin

@xedin
Copy link
Member

xedin commented Sep 22, 2019

@swift-ci create

@LucianoPAlmeida
Copy link
Collaborator

Seems like it was improved, on master is producing the following diagnostic

struct Stuff { var a: String = "" }
var stuff = Stuff()
let kp: WritableKeyPath<Stuff, String> = \Stuff.a
stuff[keyPath: kp] = "abc".prefix(1)// error: cannot assign value of type 'String.SubSequence' (aka 'Substring') to subscript of type 'String'

@xedin
Copy link
Member

xedin commented Feb 6, 2020

@LucianoPAlmeida reports that this diagnostic has been improved. @rnapier please verify using the latest nightly snapshot and resolve this issue.

@xedin
Copy link
Member

xedin commented Feb 6, 2020

@LucianoPAlmeida 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 key paths Feature: key paths (both native and Objective-C)
Projects
None yet
Development

No branches or pull requests

4 participants