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-5128] Don't allow swapping a single-tuple function with a multiple-argument function #47704

Closed
jepers opened this issue Jun 6, 2017 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@jepers
Copy link

jepers commented Jun 6, 2017

Previous ID SR-5128
Radar rdar://problem/32601618
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @rudkx
Priority Medium

md5: 313b1547b8d0b52fa35fdf2b6e23d77c

Issue Description:

Swift should properly distinguish between single-tuple and multiple-argument function types.
But it isn't, as demonstrated below.
The following is the behavior of swift-DEVELOPMENT-SNAPSHOT-2017-06-05-a-osx (-swift-version 4):

func f(_ a: Int, _ b: Int) { print("\(a), \(b)") }
func g(_ tuple: (Int, Int)) { print("\(tuple)") }
f(1, 2) // 1, 2
g((1, 2)) // (1, 2)
// Working as expected.

// But (pay close attention):
var (fCopy, gCopy) = (f, g)
fCopy(1, 2) // 1, 2
gCopy((1, 2)) // (1, 2)
swap(&fCopy, &gCopy)
fCopy(1, 2) // (1, 2)
gCopy((1, 2)) // 1, 2
// I would not expect that call to swap to compile,
// since the type parameter of swap<T> can't be both
// (Int, Int) -> () and
// ((Int, Int)) -> ().
// And also note the last two lines, where fCopy is
// actually calling g, printing its two args as a
// tuple, and gCopy actually calling f, printing its
// single tuple as two separate args.

(Reported as requested by Mark Lacey here:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170605/037013.html
)

@rudkx
Copy link
Member

rudkx commented Jun 7, 2017

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Jun 7, 2017

Thanks for all the test cases, Jens!

@slavapestov
Copy link
Member

Same issue as SR-5112.

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

No branches or pull requests

4 participants