mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This patch contains the updates for the tests. The merge removes the `-async-main` flag, so the tests using that flag fail on that. Additionally, the tests reflect the newer behavior of the main resolution. `async_main_resolution` verifies that we're not preferring an async function over a synchronous function, and vice versa. This is also verified in `where_clause_main_resolution`, where we select a main function using various configuration typealiases. Finally, we only select a valid, usable main function. The old machinery could select one sort of at random (technically it selected the first overload declared in the source file) if an error occurred. Errors that resulted in this behavior included a missing valid function, or an ambiguous overload. In the case of the missing valid function, the function returned would be from an invalid location if one existed, which was called from `$main`. `$main` had sufficient context to realize that the main function being called was not valid, and would emit an error saying why. It would be better to realize that we're not getting a valid main function earlier, and later we can emit notes saying why each function called main could not be selected.
59 lines
2.4 KiB
Swift
59 lines
2.4 KiB
Swift
// RUN: %target-swift-frontend -disable-availability-checking -D CONFIG1 -dump-ast -parse-as-library %s | %FileCheck %s --check-prefixes=CHECK,CHECK-CONFIG1
|
|
// RUN: %target-swift-frontend -disable-availability-checking -D CONFIG2 -dump-ast -parse-as-library %s | %FileCheck %s --check-prefixes=CHECK,CHECK-CONFIG2
|
|
// RUN: %target-swift-frontend -disable-availability-checking -D CONFIG3 -dump-ast -parse-as-library %s | %FileCheck %s --check-prefixes=CHECK,CHECK-CONFIG3
|
|
|
|
// REQUIRES: concurrency
|
|
|
|
protocol AppConfiguration { }
|
|
|
|
struct Config1: AppConfiguration {}
|
|
struct Config2: AppConfiguration {}
|
|
struct Config3: AppConfiguration {}
|
|
|
|
protocol App {
|
|
associatedtype Configuration: AppConfiguration
|
|
}
|
|
|
|
// Load in the source file name and grab line numbers for default main funcs
|
|
// CHECK: (source_file "[[SOURCE_FILE:[^"]+]]"
|
|
// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where
|
|
// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where
|
|
// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} App where
|
|
// CHECK: (extension_decl range={{\[}}[[SOURCE_FILE]]:{{[0-9]+}}:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}}
|
|
// CHECK-NOT: where
|
|
// CHECK-NEXT: (func_decl range={{\[}}[[SOURCE_FILE]]:[[DEFAULT_ASYNCHRONOUS_MAIN_LINE:[0-9]+]]:{{[0-9]+}} - line:{{[0-9]+}}:{{[0-9]+}}{{\]}} "main()"
|
|
// CHECK-SAME: interface type='<Self where Self : App> (Self.Type) -> () async -> ()'
|
|
|
|
extension App where Configuration == Config1 {
|
|
// CHECK-CONFIG1: (func_decl implicit "$main()" interface type='(MainType.Type) -> () -> ()'
|
|
// CHECK-CONFIG1: [[SOURCE_FILE]]:[[# @LINE+1 ]]
|
|
static func main() { }
|
|
}
|
|
|
|
extension App where Configuration == Config2 {
|
|
// CHECK-CONFIG2: (func_decl implicit "$main()" interface type='(MainType.Type) -> () async -> ()'
|
|
// CHECK-CONFIG2: [[SOURCE_FILE]]:[[# @LINE+1 ]]
|
|
static func main() async { }
|
|
}
|
|
|
|
extension App where Configuration == Config3 {
|
|
// CHECK-CONFIG3-ASYNC: (func_decl implicit "$main()" interface type='(MainType.Type) -> () async -> ()'
|
|
// CHECK-CONFIG3-ASYNC: [[SOURCE_FILE]]:[[DEFAULT_ASYNCHRONOUS_MAIN_LINE]]
|
|
}
|
|
|
|
extension App {
|
|
static func main() async { }
|
|
}
|
|
|
|
@main
|
|
struct MainType : App {
|
|
|
|
#if CONFIG1
|
|
typealias Configuration = Config1
|
|
#elseif CONFIG2
|
|
typealias Configuration = Config2
|
|
#elseif CONFIG3
|
|
typealias Configuration = Config3
|
|
#endif
|
|
}
|