Navigation Menu

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-1338] Inconsistent "Ambiguous use of 'xxx'" error when calling an Obj-C method with 2 versions that take a block with 1 or 2 parameters respectively. #43946

Open
swift-ci opened this issue Apr 27, 2016 · 1 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1338
Radar None
Original Reporter mikelehen (JIRA User)
Type Bug
Environment

Reproduced in both Xcode 7.2.1 and XCode 7.3beta.

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

md5: 805267d093e69f2bdf7e5766181c2647

relates to:

  • SR-1297 Method parameters list interpreted as a single tuple (tuple "unsplat"), making behavior disturbing

Issue Description:

See https://github.com/mikelehen/swift-ambiguous-use-bug for a repro.

Basically, SwiftBug.h defines a class with two versions of a "observeEventType" method:

  • (void)observeEventType:(int)eventType withBlock:(void (^)(Thinger *thing))block;

  • (void)observeEventType:(int)eventType andPreviousSiblingKeyWithBlock:(void (^)(Thinger *thing, NSString *key))block;

I'm able to inconsistently call this method with trailing closure syntax. And very strangely, the presence of an innocuous print statement causes compilation to fail:

        foo.observeEventType(0) { snap in
            // If you uncomment print("test") then compilation fails with "Ambiguous use of 'observeEventType(_:withBlock:)'"
            //print("test")
            
            snap.doThing()
        }

Can you:

  1. Confirm there's a bug here and comment on if/when it might be fixed.
  2. Comment on the best way to expose this method so that Swift trailing closure syntax works (ideally I would just expose the version that takes the block with two params, but I want both versions for Obj-C).

Thanks!

@belkadan
Copy link
Contributor

Hm. I suppose this is similar to SR-1297, in that we shouldn't allow this syntax to match the two-argument case. You can work around it by explicitly providing a type:

foo.observeEventType(0) { (snap: Thinger) in

Unfortunately I can't speak to when this might be fixed. Given that there's a workaround, and the situation isn't too common to begin with, it's not something that usually gets a high priority.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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