swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.69k stars 10.39k forks source link

[SR-3865] A possible tuple-inference/parameter-resolution bug in Swift 3.0.1 #46450

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
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:

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

belkadan commented 7 years ago

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

slavapestov commented 7 years ago

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 commented 7 years ago

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!