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-12243] Inconsistent rules of inner function ordering and compiler crash #54670

Open
jepers opened this issue Feb 20, 2020 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@jepers
Copy link

jepers commented Feb 20, 2020

Previous ID SR-12243
Radar rdar://problem/59655526
Original Reporter @jepers
Type Bug
Environment

Default toolchain of Xcode 11.3.1 (11C504)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 3f9adb11ddeabc3ca9a3eab89a9aeb68

Issue Description:

Program A (compiles and runs):

func foo() {
    {
        bar()
    }()
    if true {
        return
    }
    func bar() {
        print("bar")
    }
}
foo()

Since A compiles and runs, printing bar, I'd expect the following two programs B and C to compile and run too.

But program B will crash the compiler, and program C will result in a compile time error (which is inconsistent with program A being valid).

So either program A is an example of accepts invalid, or B and C should compile.

Program B (crashes compiler):

func foo() {
    {
        bar()
    }()
    //if true {
        return
    //}
    func bar() {
        print("bar")
    }
}
foo()

Program C (inconsistent error (given that A compiles)):

func foo() {
    //{
        bar() // ERROR: Use of local variable 'bar' before its declaration
    //}()
    //if true {
        return
    //}
    func bar() {
        print("bar")
    }
}
foo()

Related forum post:
https://forums.swift.org/t/improve-nested-functions-visibility-or-order-dependency/33935/8

@hborla
Copy link
Member

hborla commented Feb 21, 2020

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

No branches or pull requests

2 participants