Skip to content

[SR-13426] Code completion inserting invalid key path code when contextual type has optional root #55867

@LucianoPAlmeida

Description

@LucianoPAlmeida
Previous ID SR-13426
Radar None
Original Reporter @LucianoPAlmeida
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Xcode 12 Beta 1 Swift 5.3

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

md5: a1df7824b85ed7ba81bc9ad88e92c0eb

Issue Description:

When having a contextual key path type with an optional root

struct A {
  var property: String
}
let keyPath: KeyPath<A?, String> = \.#^COMPLETION^#

Code completion gives those options
![](Screen Shot 2020-08-20 at 22.11.48-1.png)

And when selecting a property, the inserted code is invalid

![](Screen Shot 2020-08-20 at 22.12.17.png)

Because `?.property` is not acceptable since inferring key path root type as an optional is not supported. The problem is that we also cannot`.property` because it would not be able to convert the inferred non-optional root to the optional contextual root.

So I'm not sure what would be a solution to this, maybe not allow declarations of a key path with optional root...

Metadata

Metadata

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.code completionArea → source tooling: code completioncompilerThe Swift compiler itselfsource toolingArea: IDE support, SourceKit, and other source tooling

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions