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-8611] Ambiguous use subscript on protocol and class through AnyObject lookup #51126

Closed
hamishknight opened this issue Aug 22, 2018 · 4 comments
Assignees
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

@hamishknight
Copy link
Collaborator

Previous ID SR-8611
Radar rdar://problem/43645564
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Done
Environment

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0

Swift version 4.2-dev (LLVM 6e538a505a, Clang 9dd0997a35, Swift f93362037c)
Target: x86_64-apple-darwin17.7.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee @hamishknight
Priority Medium

md5: 2ac189153df3507d116b2a5979802cbf

Issue Description:

The following raises an ambiguity error:

import Foundation

@objc protocol P {
  @objc subscript(foo _: Int) -> Int { get }
}

class C {
  @objc subscript(foo _: Int) -> Int { return 0 }
}

func foob(_ x: AnyObject) {
  _ = x[foo: 6] // error: Ambiguous use of 'subscript(foo:)'
}

Despite the fact that there's only one viable selector and return type for the call.

@belkadan
Copy link
Contributor

I don't think there's any coalescing of common signatures today, is there?

@hamishknight
Copy link
Collaborator Author

We do for methods and properties, for example:

import Foundation

@objc protocol P {
  @objc var foo: Int { get }
  @objc func bar() -> Int
}

class C {
  @objc var foo: Int = 0
  @objc func bar() -> Int { return 0 }
}

func foob(_ x: AnyObject) {
  // All okay.
  _ = x.foo
  _ = x.bar()
  _ = x.bar
}

@belkadan
Copy link
Contributor

Huh, okay. I did not realize this.

@swift-ci create

@hamishknight
Copy link
Collaborator Author

Fixed by #31753

@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

2 participants