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-6451] Initializer is able to recursively call itself with no warnings #49001

Closed
colemancda opened this issue Nov 21, 2017 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@colemancda
Copy link
Contributor

Previous ID SR-6451
Radar None
Original Reporter @colemancda
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Swift 4.1 development snapshot on Ubuntu 16.04

swift-4.1-DEVELOPMENT-SNAPSHOT-2017-11-20-a-ubuntu16.04.tar.gz

Also tried in Ubuntu 16.10

swift-4.1-DEVELOPMENT-SNAPSHOT-2017-11-20-a-ubuntu16.10.tar.gz

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

md5: af8609b588fceb597731dd9852454e34

duplicates:

  • SR-626 No diagnostic for unconditional recursion

Issue Description:

Any initializer can be called recursively and the compiler will emit no warnings. The resulting code will crash at runtime with an non-descriptive error (Segmentation Fault). The Swift compiler should not allow initializers to call themselves recursively, unlike methods or functions there is no scenario where this will not crash.

struct Value {
    let value: Int
    init(_ value: Int) {
        self.init(value)
    }
}
 
let value = Value(1) // crash

Here are other reproducible examples:

https://user-images.githubusercontent.com/2727770/164962448-399c6ca2-849e-45ac-a724-8be99343d0cc.gz

http://swift.sandbox.bluemix.net/#/repl/5a15f40343e1ee1b72bcd2f9

http://swift.sandbox.bluemix.net/#/repl/5a15f8d243e1ee1b72bcd2fb

@colemancda
Copy link
Contributor Author

Can also reproduce with Cacao v0.6.2 and swift-4.1-DEVELOPMENT-SNAPSHOT-2017-11-20-a-ubuntu16.10.tar.gz

swift package update
swift build
.build/x86_64-unknown-linux/debug/CacaoDemo

The same code compiles and runs fine with Xcode and on Linux with swift-DEVELOPMENT-SNAPSHOT-2017-06-26-a-ubuntu16.10.tar.

swift build
.build/debug/CacaoDemo

@colemancda
Copy link
Contributor Author

  • Build with `swift build`
  • Execute `CacaoDemo`
  • See segmentation fault crash.

Upon debugging, the crash occurs when UIView's initializer is called.

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

No branches or pull requests

1 participant