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-8109] Swift 4.2 Regression: Single-element tuple not prevented #50641

Closed
jepers opened this issue Jun 26, 2018 · 6 comments
Closed

[SR-8109] Swift 4.2 Regression: Single-element tuple not prevented #50641

jepers opened this issue Jun 26, 2018 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.2

Comments

@jepers
Copy link

jepers commented Jun 26, 2018

Previous ID SR-8109
Radar rdar://problem/41474370
Original Reporter @jepers
Type Bug
Status Closed
Resolution Done
Environment

Xcode 10 beta 1, Xcode 10 beta 2, recent dev snapshots

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

md5: a1a43661b0f49d77dcf52bd812ef1d1e

Issue Description:

Related thread (which I wish got some clarifications from the core team): https://forums.swift.org/t/roadmap-for-and-state-of-single-element-tuple-types/13711

As far as I understand, single element tuples should be prevented in Swift.

The following program does not compile with (the default toolchain of) Xcode 9.4, as expected.

BUT with recent versions of the compiler (default toolchains of Xcode 10 beta 1 and beta 2, as well as recent dev snapshots), it does compile.

let t = (label: 123)
print(t.label + t.label) // prints 246

So we can define `t` to be of an instance of a (labeled) single-element tuple type, and use it as such.

(
But we cannot dump or print or otherwise access its type without getting (nonsensical) errors, and we cannot define its type explicitly, meaning the following will not compile:

let t: (label: Int) = (label: 123)
print(t.label + t.label)

)

Also, as a side note, the following program compiles with all versions of the compiler (including Xcode 9.4):

let r = (label: 12).label + (label: 34).label
print(r) // prints 46

But I guess it shouldn't?

@belkadan
Copy link
Contributor

Thanks, Jens.

@swift-ci create

@rudkx
Copy link
Member

rudkx commented Jun 27, 2018

I suspect this is a result of my change to eliminate exponential behavior in expression type checking for tuple expressions.

@jepers
Copy link
Author

jepers commented Oct 11, 2018

Issue still remains in default toolchain of Xcode 10.
I suppose this related example shouldn't compile either:

let t = (singleElementTupleLabel: 123).singleElementTupleLabel

?

@swift-ci
Copy link
Collaborator

Comment by Tim (JIRA)

With the latest master toolchain `let t = (label: 123)` no longer compiles, instead it results in Abort trap: 6.

@slavapestov
Copy link
Member

#21349

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 23, 2019

@jepers, Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

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

No branches or pull requests

6 participants