Skip to content

[SR-677] Infinite recursion instead of compiler error - overwritten function #43292

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

Closed
swift-ci opened this issue Feb 4, 2016 · 2 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Feb 4, 2016

Previous ID SR-677
Radar None
Original Reporter roman.kriz (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OS X: 10.11.4 Beta (15E33e)
Swift 2.1.1 (Xcode 7.2.1 (7C1002)) and also in 2.2 (Xcode 7.3 beta (7D129n))

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @CodaFi
Priority

md5: 80de1a1ee66b648a64a4bc5c1d474510

relates to:

  • SR-626 No diagnostic for unconditional recursion

Issue Description:

I found pretty weird bug in this example code:

func tr(key key: String) -> String? {
    return key
}

func tr(key: String) -> String {
    return tr(key) ?? key
}

tr("abc")

This code is causing infinite loop because

  • first function

    tr(key:)
    

    has label for first argument

  • second function

    tr(_:)
    

    has no label and is naively calling the first function because it returns optional (but writer of this code forgot about the label)

Since the operator ?? can be used when left value is non-optional this is complete valid expression, but there should be at least warning for that case, right?

@belkadan
Copy link
Contributor

belkadan commented Feb 5, 2016

I think you meant "naively calling the second function". @jopamer, here's an example of where "implicit conversion to optional from non-optional" is a problem!

(We could also warn on infinite recursion, like Clang does, but that wouldn't catch all instances of this mistake—say, within the body of an if statement.)

@CodaFi
Copy link
Contributor

CodaFi commented Feb 27, 2018

Resolved by the merge of #11869.

@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself
Projects
None yet
Development

No branches or pull requests

3 participants