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-5114] Not correct function types in Swift4 (is) #47690

Closed
swift-ci opened this issue Jun 6, 2017 · 3 comments
Closed

[SR-5114] Not correct function types in Swift4 (is) #47690

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

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 6, 2017

Previous ID SR-5114
Radar rdar://problem/32601621
Original Reporter VladimirS (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 53fd0901e0a7d90f1840cd1b3ad7180a

Issue Description:

Mark Lacey <mark.lacey@apple.com> asked to create this issue. ("is" part)

I believe fooParam should have type of (Int,Int) -> () and fooTuple of type ((Int,Int)) -> (), but it seems like they have the same type:

func fooParam(_ x: Int, _ y: Int){}
func fooTuple(_ x: (Int, Int)) {}

if fooParam is (_: (Int,Int))->() { print("fooParam is (_: (Int,Int))->()") }
// result: fooParam is (_: (Int,Int))->()

if fooTuple is (Int,Int)->() { print("fooTuple is (Int,Int)->()") }
// result: fooTuple is (Int,Int)->()

//--- closure ---

var closureParam = { (x: Int, y: Int) in  }
var closureTuple = { (x: (Int, Int)) in  }

if closureParam is (_: (Int,Int))->() { print("closureParam is (_: (Int,Int))->()") }
// result: closureParam is (_: (Int,Int))->()

if closureTuple is (Int,Int)->() { print("closureTuple is (Int,Int)->()") }
// result: closureTuple is (Int,Int)->()
@rudkx
Copy link
Member

rudkx commented Jun 7, 2017

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Jun 7, 2017

This is a result of canonicalizing in typeCheckCheckedCast. We test equality, which uses the canonical types, which strips parens.

Even if we “fix” that, we end up in TypeChecker::isConvertibleTo(), which eventually leads to matchTypes, which eventually does the same equality test because we’re testing a conversion constraint, and the code in matchTypes does not try to avoid the canonicalization in that case like it does for argument tuple conversions.

@slavapestov
Copy link
Member

This was resolved in Swift 5 when the function type representation was redone.

@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

3 participants