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

Top-level multi-variable single declaration with closure bug #62940

Open
joehinkle11 opened this issue Jan 10, 2023 · 1 comment
Open

Top-level multi-variable single declaration with closure bug #62940

joehinkle11 opened this issue Jan 10, 2023 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. closures Feature: closures compiler The Swift compiler in itself expressions Feature: expressions let & var Feature: constant and variable declarations mangling Area → compiler: Mangling multiple files Flag: An issue whose reproduction requires multiple files swift 6.0 unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@joehinkle11
Copy link

Description
Initializing multiple top-level variables in a single declaration where the all the initializations are immediately invoked closures causes the later variables' initialization to be overridden by the first's.

Steps to reproduce
Make a simple Swift Package with two files.

// main.swift
print(x) // prints "x" as expected
print(y) // prints "x" when "y" was expected
// other.swift
let x = {return "x"}(), y = {return "y"}()

Screenshots

image

image

image

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0
  • Xcode version info: Xcode 14.2 Build version 14C18
  • Deployment target: Mac
@joehinkle11 joehinkle11 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 10, 2023
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself global let & var Feature: global constants and variables memory corruption and removed triage needed This issue needs more specific labels labels Jan 12, 2023
@AnthonyLatsis AnthonyLatsis added SILGen Area → compiler: The SIL generation stage multiple files Flag: An issue whose reproduction requires multiple files swift 6.0 closures Feature: closures expressions Feature: expressions and removed swift 5.7 labels Jan 11, 2024
@jckarter jckarter added mangling Area → compiler: Mangling and removed SILGen Area → compiler: The SIL generation stage labels Jan 11, 2024
@jckarter
Copy link
Contributor

jckarter commented Jan 11, 2024

The mangler mangles both closures with the same symbol name $s4fooo1xSSvpfiSSyXEfU_ "closure #1 in variable initialization expression of x", causing the closure for initializing y to never get emitted because we pick up the one for x in its stead.

@AnthonyLatsis AnthonyLatsis added let & var Feature: constant and variable declarations unexpected behavior Bug: Unexpected behavior or incorrect output and removed memory corruption global let & var Feature: global constants and variables labels Jan 17, 2024
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. closures Feature: closures compiler The Swift compiler in itself expressions Feature: expressions let & var Feature: constant and variable declarations mangling Area → compiler: Mangling multiple files Flag: An issue whose reproduction requires multiple files swift 6.0 unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

No branches or pull requests

3 participants