mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The main change is to detect infinite recursive calls under invariant conditions. For example:
func f() {
if #available(macOS 10.4.4, *) {
f()
}
}
or invariant conditions due to forwarded arguments:
func f(_ x: Int) {
if x > 0 {
f(x)
}
}
Also, improve the warning message. Instead of giving a warning at the function location
warning: all paths through this function will call itself
give a warning at the call location:
warning: function call causes an infinite recursion
Especially in case of multiple recursive calls, it makes it easier to locate the problem.
https://bugs.swift.org/browse/SR-11842
rdar://57460599
28 lines
580 B
Swift
28 lines
580 B
Swift
// RUN: %target-swift-frontend -emit-sil -primary-file %s -o /dev/null -verify
|
|
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: OS=macosx
|
|
|
|
// A negative test that the infinite recursion pass doesn't diagnose dynamic
|
|
// dispatch.
|
|
|
|
import Foundation
|
|
|
|
class MyRecursiveClass {
|
|
required init() {}
|
|
@objc dynamic func foo() {
|
|
return type(of: self).foo(self)()
|
|
}
|
|
|
|
@objc dynamic func foo2() {
|
|
return self.foo()
|
|
}
|
|
}
|
|
|
|
func insideAvailability() {
|
|
if #available(macOS 10.4.4, *) {
|
|
insideAvailability() // expected-warning {{function call causes an infinite recursion}}
|
|
}
|
|
}
|
|
|