swiftlang / swift

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

Generic argument list incorrectly allowed on member #74857

Open hamishknight opened 1 week ago

hamishknight commented 1 week ago

This is incorrectly allowed to compile:

let x = "".count<Array>
AnthonyLatsis commented 6 days ago

Has to do with literals:

extension Int {
  func foo() -> Int {}
  var bar: Int {
    get {}
  }
}

func test(i: Int) {
  // Error
  let _ = i.foo<Int>()
  let _ = i.bar<Int>

  // OK
  let _ = 0.foo<Int>()
  let _ = 0.bar<Int>
}
hamishknight commented 6 days ago

Really it's anything that isn't immediately resolved in CSGen, e.g:

extension Int {
  func foo() -> Int { 0 }
  func foo(_ x: Int = 0) -> Int { 0 }
}

func test(i: Int) {
  let _ = i.foo<Int>
}