Skip to content

[Typechecker] Covariant subscript check must also take into consideration mismatched types #29828

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

Merged
merged 1 commit into from
Feb 15, 2020
Merged

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Feb 13, 2020

When we override a settable subscript with a different argument type, the compiler emits an error complaining that the types are not covariant:

class A {
  subscript (foo: Int) -> Int {
    get { fatalError() }
    set {}
  }
}
class B: A {
  override subscript (foo: String) -> Int {
    get { fatalError() }
    set {}
  }
}

The compiler currently emits an error saying cannot override mutable subscript of type '(Int) -> Int' with covariant type '(String) -> Int', but the argument types (Int and String) are unrelated.

We should make sure that we don't have mismatched types, so we can print the right diagnostics.

Resolves SR-10323

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

@theblixguy theblixguy merged commit a0d3542 into swiftlang:master Feb 15, 2020
@theblixguy theblixguy deleted the fix/SR-10323 branch February 15, 2020 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants