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-15264] Tuple construction should preserve full expression in type-checked AST #57586

Open
hamishknight opened this issue Sep 30, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-15264
Radar rdar://problem/83714569
Original Reporter @hamishknight
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 95b86d530d86dd2a243c84a8d6b97f65

Issue Description:

For a tuple construction expr such as:

(String, String)("", "")

(yes, this is legal Swift!)

We currently type-check this by transforming the argument list into a tuple, and coercing it to the destination tuple type. This works fine for regular compilation, however for interface generation it means we end up with ("", "") instead of (String, String)("", "") if written as e.g a default argument.

Ideally we'd preserve the full expression, probably by introducing an AST node to represent this conversion in type-checked AST. This is especially important for cases where the destination tuple type is required for the expression to be re-type-checked properly, e.g (Substring, Substring)("", "") or (Int?, Int?)(nil, nil).

I'm not sure if this has compatibility implications, as e.g a function with a default argument:

public func foo(arg: Any = (Substring, Substring)("", "")) {}

is currently being exposed to clients as:

public func foo(arg: Any = ("", ""))

so adding back the missing type information may change how it is type-checked.

@hamishknight
Copy link
Collaborator Author

@swift-ci create

@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
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

1 participant