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

Better diagnostic when type has constrained subscript setter override #72810

Open
stephencelis opened this issue Apr 3, 2024 · 0 comments
Open
Labels
feature A feature request or implementation triage needed This issue needs more specific labels

Comments

@stephencelis
Copy link
Contributor

stephencelis commented Apr 3, 2024

Motivation

Calling a method on a type that is unavailable due to an unmatched conformance does provide a diagnostic that leads the user in the right direction.

For example:

struct A<B> {
  var c: Int {
    fatalError()
  }
  subscript(position: Int) -> B {
    fatalError()
  }
}

extension A where B: Equatable {
  var c: Int {
    get { fatalError() }
    set { fatalError() }
  }
  subscript(position: Int) -> B {
    get { fatalError() }
    set { fatalError() }
  }
  func f() -> Int { fatalError() }
}

func f() {
  let a = A<()>()
  a.c = 42  // 👎 Cannot assign to property: 'c' is a get-only property
  a[0] = () // 👎 Cannot assign through subscript: subscript is get-only
  a.f()     // 👍 Type '()' cannot conform to 'Equatable'
}

Proposed solution

I think it would be nice to provide a diagnostic that includes this kind of hint. For example:

a.c = 42  // 👍 Cannot assign to property: '()' does not conform to 'Equatable'
a[0] = () // 👍 Cannot assign through subscript: '()' does not conform to 'Equatable'
a.f()     // 👍 Type '()' cannot conform to 'Equatable'

Alternatives considered

No response

Additional information

No response

@stephencelis stephencelis added feature A feature request or implementation triage needed This issue needs more specific labels labels Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant