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-1721] Nested functions need to be defined in code before they are used #44330

Closed
swift-ci opened this issue Jun 9, 2016 · 4 comments
Closed

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jun 9, 2016

Previous ID SR-1721
Radar None
Original Reporter mariano (JIRA User)
Type Improvement
Status Resolved
Resolution Won't Do

Attachment: Download

Additional Detail from JIRA
Votes 1
Component/s
Labels Improvement
Assignee None
Priority Medium

md5: 005ce6eb0b9b937beb33bb4e499a7a2f

Issue Description:

One approach to using nested functions is grouping pieces of code, for instance, configuration of several views in a function called `configureViews`.

In such task, the natural way of looking at it would be to call the functions first, as they serve as a sort of summary, and then define the functions later.

Doing so will result in the following error being displayed:
`Use of local variable `[functionName]` before its declaration`

See attached Playground.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jun 9, 2016

Since nested functions can capture local variables, the place where they are declared is significant.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Jun 9, 2016

Comment by Mariano Abdala (JIRA)

Then I would understand that variables are defined before the functions are, and that variables are defined before the functions are invoked, but not that definition of functions need to precede its invocation. At least from a Swift `consumer` side.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jun 9, 2016

That's not sufficient when a variable (as opposed to a constant) is captured by value (using a capture list). You have to know when the capture happens to know what the value is.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Jun 9, 2016

Comment by Mariano Abdala (JIRA)

Cool, just trying to understand. Thanks.

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

No branches or pull requests

2 participants