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-5578] Partial key paths don't provide enough type context to omit the base of a key path literal #48150

Closed
swift-ci opened this issue Jul 29, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5578
Radar rdar://problem/33223731
Original Reporter Vermeulen (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 77f6df55845c3cd2d13cc210bf78782e

duplicates:

  • SR-5667 Type inference for Swift 4 KeyPaths fails within collections

Issue Description:

Using the 7/28 master brach toolchain:

struct Bar {}
struct Foo { let bar: Bar }

func foo(_ bar: PartialKeyPath<Foo>) {}
foo(\.bar) // Type of expression is ambiguous without more context
@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Tim (JIRA)

It's worth noting that this compiles fine:

struct Bar {}
struct Foo { let bar: Bar }
let fooBar: PartialKeyPath<Foo> = \.bar

@swift-ci
Copy link
Collaborator Author

Comment by Basem Emara (JIRA)

Not sure if this is related, but also fails with the same compile error:

struct MyType {
    let prop1: String
    let prop2: Int
    let prop3: Bool
}

func test(_ keyPath: PartialKeyPath<MyType>) {
    switch keyPath {
    case \MyType.prop1:
        print("prop1")
    case \MyType.prop2:
        print("prop2")
    case \MyType.prop3:
        print("prop3")
    case \.prop3: // Compile error: Type of expression is ambiguous without more context
        print("prop3b")
    default:
        break
    }
}

test(\MyType.prop1)

@LucianoPAlmeida
Copy link
Collaborator

Resolving as duplicated

cc @xedin

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants