Files
swift-mirror/test/SILOptimizer/infinite_recursion_objc.swift
Erik Eckstein d824fd3440 DiagnoseInfiniteRecursion: handle invariant conditions and improve the warning message
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
2021-01-13 14:35:03 +01:00

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}}
}
}