swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.49k stars 10.35k forks source link

`@dynamicMemberLookup` static subscripts do not work with unprefixed dot syntax #60574

Open matt-curtis opened 2 years ago

matt-curtis commented 2 years ago

Describe the bug @dynamicMemberLookup static subscripts do not work with unprefixed dot syntax.

Demonstration:

struct Color {

    let red: Double
    let green: Double
    let blue: Double
    let alpha: Double

}

@dynamicMemberLookup
struct Prop {

    static subscript<T>(dynamicMember member: KeyPath<Color, T>) -> Self { Prop() }

}

_ = Prop.red // works
let prop: Prop = .red // does not work

Steps To Reproduce Steps to reproduce the behavior:

  1. Define a static dynamicMember subscript
  2. Observe that it does not work with unprefixed dot syntax

Expected behavior Dynamic properties are inferred the same way as other unprefixed properties are.

Environment (please fill out the following information)

Additional context Swift forums thread post discussing this issue.

soumyamahunt commented 1 year ago

Looking forward for this to be fixed as well.