Files
swift-mirror/test/expr/capture/generic_params.swift
Vinicius Vendramini 39d3963131 Fix broken tests
- Many tests got broken because of two things:
  - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix.
  - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence.

Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
2018-11-14 13:38:01 -02:00

35 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -dump-ast %s | %FileCheck %s
func doSomething<T>(_ t: T) {}
// CHECK: func_decl{{.*}}"outerGeneric(t:x:)" <T> interface type='<T> (t: T, x: AnyObject) -> ()'
func outerGeneric<T>(t: T, x: AnyObject) {
// Simple case -- closure captures outer generic parameter
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=0 captures=(<generic> t<direct>) escaping single-expression
_ = { doSomething(t) }
// Special case -- closure does not capture outer generic parameters
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=1 captures=(x<direct>) escaping single-expression
_ = { doSomething(x) }
// Special case -- closure captures outer generic parameter, but it does not
// appear as the type of any expression
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=2 captures=(<generic> x<direct>)
_ = { if x is T {} }
// Nested generic functions always capture outer generic parameters, even if
// they're not mentioned in the function body
// CHECK: func_decl{{.*}}"innerGeneric(u:)" <U> interface type='<T, U> (u: U) -> ()' {{.*}} captures=(<generic> )
func innerGeneric<U>(u: U) {}
// Make sure we look through typealiases
typealias TT = (a: T, b: T)
// CHECK: func_decl{{.*}}"localFunction(tt:)" interface type='<T> (tt: TT) -> ()' {{.*}} captures=(<generic> )
func localFunction(tt: TT) {}
// CHECK: closure_expr type='((a: T, b: T)) -> ()' {{.*}} captures=(<generic> )
let _: (TT) -> () = { _ in }
}