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-11711] #if interferes with return-less bodies #54119

Closed
dabrahams opened this issue Nov 5, 2019 · 4 comments
Closed

[SR-11711] #if interferes with return-less bodies #54119

dabrahams opened this issue Nov 5, 2019 · 4 comments
Labels
compiler The Swift compiler in itself improvement parser Area → compiler: The legacy C++ parser

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-11711
Radar rdar://problem/56923070
Original Reporter @dabrahams
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, Parser
Assignee maustinstar (JIRA)
Priority Medium

md5: dbe62f528523cd6659e93f772ae6f49d

Issue Description:

This is a shame:

var x: Int {
    0 // OK
}

var y: Int {
    #if false
    return 0 // OK
    #else
    return 1 // OK
    #endif
}


var z: Int {
    #if false
    0
    #else
    1 // error: missing return in a function expected to return 'Int'; did you mean to return the last expression?
    #endif
}

It would be a really useful and clean idiom to use with platform tests, were it legal

@beccadax
Copy link
Contributor

beccadax commented Nov 5, 2019

@swift-ci create

@beccadax
Copy link
Contributor

beccadax commented Nov 5, 2019

This doesn't seem too difficult to do—I'm tempted to label it a starter bug. We recognize single-expression functions in Parser::parseAbstractFunctionBody(); I think we could just look for an IfConfigDecl there and step into its active clause, probably in a loop.

@dabrahams @DougGregor Would this be a bug fix or would it require an evolution proposal?

@DougGregor
Copy link
Member

It’sa bug fix. No Evolution proposal required

@swift-ci
Copy link
Collaborator

Comment by Michael Verges (JIRA)

Pull Request: #34510

@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
compiler The Swift compiler in itself improvement parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

4 participants