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-3865] A possible tuple-inference/parameter-resolution bug in Swift 3.0.1 #46450

Open
swift-ci opened this issue Feb 5, 2017 · 3 comments
Open

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Feb 5, 2017

Previous ID SR-3865
Radar None
Original Reporter mvonballmo (JIRA User)
Type Bug

Attachment: Download

Environment

XCode Version 8.2.1 (8C1002), MacOS 10.12.3 (16D32)

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

md5: f458cd138c0b5cd9ccfb13befee8169d

Issue Description:

The following code compiles and yields somewhat unexpected results.

func test<T>(_ a: T) -> String
{
  return String(describing: type(of: T.self))
}

var int = test(1)
var odd = test(1, 2)
var tuple = test((1, 2))
var labels = test(a: 1, b: 2)
var nestedTuple = test(((1, 2)))
var complexTuple = test((1, (2, 3)))

Here are the results in the Playground:

With argument label looks fine:

Without argument label seems strange:

  • odd: Swift interpreted the two parameters as a Tuple. Is that correct, though? Are the parentheses allowed to serve double-duty both as part of the function-call expression and as part of the tuple expression?

  • labels: The issue with double-duty parentheses isn’t limited to anonymous tuples. The compiler treats what looks like two labeled function-call parameters as a tuple with two Ints labeled {a:} and {b:}.

  • nestedTuple: This is not a tuple of a tuple, but just a two-element tuple

I wrote up more details on my blog before I discovered that this issue-tracker for Swift.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Feb 7, 2017

@slavapestov, I thought we managed to destroy these? I do see the errors in Swift 4 mode.

@slavapestov
Copy link
Member

@slavapestov slavapestov commented Feb 7, 2017

Do or don't see the errors in Swift 4 mode?

it behaves as expected for me:

tup.swift:7:19: error: extra argument in call
var odd = test(1, 2)
                  ^
tup.swift:9:28: error: extra argument 'b' in call
var labels = test(a: 1, b: 2)
                           ^

Marco, in Swift 3, the proposal to disambiguate argument lists from tuple arguments (SE-0110) was not fully implemented. On master (you can try the latest snapshot if you want), enabling Swift 4 mode will make the suspect cases into type errors.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Feb 7, 2017

Comment by Marco von Ballmoos (JIRA)

@slavapestov: Thanks for the tip about Swift 4 mode. I have a workaround for it, but wanted to report the bug in case you weren't aware of it. Thanks for the quick responses!

@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
Projects
None yet
Development

No branches or pull requests

3 participants