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-12432] Regression: "Key path cannot refer to static member" setting default property value #54871

Open
swift-ci opened this issue Mar 27, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12432
Radar rdar://problem/62200994
Original Reporter davidhun (JIRA User)
Type Bug

Attachment: Download

Environment

swift --version

Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)

Target: x86_64-apple-darwin19.4.0

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

md5: 60785f87f86d26e9c114cf80687ec958

Issue Description:

In Swift 5.2 I am unable to set a default property value that contains a KeyPath. If the same code is written in the initializer it works fine. This code compiles fine on Swift 5.1.3 both MacOS and Linux.

``` swift

struct MyStruct1: I18nBindable {

**let** text: I18nString

**init**() {

    **self**.text = **Self**.t(for: \*Self\*.text) // \<– works fine

}

}

struct MyStruct2: I18nBindable {

**let** text: I18nString = **Self**.t(for: \*Self\*.text) // \<– Error: "Key path cannot refer to static member 'text'" – (this worked in Swift 5.1.3, but fails in 5.2)

}

```

Full details in text.swift

Steps to reproduce:

  1. Install Swift 5.2 (Xcode Version 11.4 (11E146)) on MacOS 10.15.4 (19E266)

  2. swift test.swift

Expected result: compiles successfully

Received result:

test.swift:20:46: error: key path cannot refer to static member 'text'

let text: I18nString = Self.t(for: \Self.text) // \<– Error: "Key path cannot refer to static member 'text'" – (this worked in Swift 5.1.3, but fails in 5.2)
@beccadax
Copy link
Contributor

@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
Projects
None yet
Development

No branches or pull requests

2 participants