// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module -o %t %s -import-objc-header %S/Inputs/imported-block-typedefs.h -disable-objc-attr-requires-foundation-module
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/imported-block-typedefs.swiftmodule -typecheck -emit-objc-header-path %t/imported-block-typedefs-output.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module 2>%t/stderr.txt
// RUN: %FileCheck %s --input-file %t/imported-block-typedefs-output.h
// RUN: %FileCheck --check-prefix ERROR %s --input-file %t/stderr.txt
// RUN: %check-in-clang %t/imported-block-typedefs-output.h -include %S/Inputs/imported-block-typedefs.h

// REQUIRES: objc_interop

// ERROR-DAG: <unknown>:0: warning: implicit import of bridging header 'imported-block-typedefs.h' via module 'main' is deprecated and will be removed in a later version of Swift
// ERROR-NOT: warning: arbitrarily printing

import ObjectiveC

// CHECK-LABEL: @interface Typedefs
@objc class Typedefs {
  
  // FIXME: The importer loses __attribute__((noescape)) for params of imported function types.
  // https://github.com/apple/swift/issues/45134
  
  // CHECK-NEXT: - (void)noescapeParam1:(SWIFT_NOESCAPE PlainBlock _Nonnull)input;
  // CHECK-NEXT: - (void)noescapeParam2:(SWIFT_NOESCAPE BlockWithEscapingParam _Nonnull)input;
  // CHECK-NEXT: - (void)noescapeParam3:(SWIFT_NOESCAPE BlockWithNoescapeParam _Nonnull)input;
  // CHECK-NEXT: - (void)noescapeParam4:(SWIFT_NOESCAPE BlockReturningBlockWithEscapingParam _Nonnull)input;
  // CHECK-NEXT: - (void)noescapeParam5:(SWIFT_NOESCAPE BlockReturningBlockWithNoescapeParam _Nonnull)input;
  @objc func noescapeParam1(_ input: PlainBlock) {}
  @objc func noescapeParam2(_ input: BlockWithEscapingParam) {}
  @objc func noescapeParam3(_ input: BlockWithNoescapeParam) {}
  @objc func noescapeParam4(_ input: BlockReturningBlockWithEscapingParam) {}
  @objc func noescapeParam5(_ input: BlockReturningBlockWithNoescapeParam) {}
  
  // CHECK-NEXT: - (void)escapingParam1:(PlainBlock _Nonnull)input;
  // CHECK-NEXT: - (void)escapingParam2:(BlockWithEscapingParam _Nonnull)input;
  // CHECK-NEXT: - (void)escapingParam3:(BlockWithNoescapeParam _Nonnull)input;
  // CHECK-NEXT: - (void)escapingParam4:(BlockReturningBlockWithEscapingParam _Nonnull)input;
  // CHECK-NEXT: - (void)escapingParam5:(BlockReturningBlockWithNoescapeParam _Nonnull)input;
  @objc func escapingParam1(_ input: @escaping PlainBlock) {}
  @objc func escapingParam2(_ input: @escaping BlockWithEscapingParam) {}
  @objc func escapingParam3(_ input: @escaping BlockWithNoescapeParam) {}
  @objc func escapingParam4(_ input: @escaping BlockReturningBlockWithEscapingParam) {}
  @objc func escapingParam5(_ input: @escaping BlockReturningBlockWithNoescapeParam) {}
  
  // CHECK-NEXT: - (void (^ _Nonnull)(SWIFT_NOESCAPE PlainBlock _Nonnull))resultHasNoescapeParam1 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(SWIFT_NOESCAPE BlockWithEscapingParam _Nonnull))resultHasNoescapeParam2 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(SWIFT_NOESCAPE BlockWithNoescapeParam _Nonnull))resultHasNoescapeParam3 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(SWIFT_NOESCAPE BlockReturningBlockWithEscapingParam _Nonnull))resultHasNoescapeParam4 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(SWIFT_NOESCAPE BlockReturningBlockWithNoescapeParam _Nonnull))resultHasNoescapeParam5 SWIFT_WARN_UNUSED_RESULT;
  @objc func resultHasNoescapeParam1() -> (PlainBlock) -> () { fatalError() }
  @objc func resultHasNoescapeParam2() -> (BlockWithEscapingParam) -> () { fatalError() }
  @objc func resultHasNoescapeParam3() -> (BlockWithNoescapeParam) -> () { fatalError() }
  @objc func resultHasNoescapeParam4() -> (BlockReturningBlockWithEscapingParam) -> () { fatalError() }
  @objc func resultHasNoescapeParam5() -> (BlockReturningBlockWithNoescapeParam) -> () { fatalError() }
  
  // CHECK-NEXT: - (void (^ _Nonnull)(PlainBlock _Nonnull))resultHasEscapingParam1 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(BlockWithEscapingParam _Nonnull))resultHasEscapingParam2 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(BlockWithNoescapeParam _Nonnull))resultHasEscapingParam3 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(BlockReturningBlockWithEscapingParam _Nonnull))resultHasEscapingParam4 SWIFT_WARN_UNUSED_RESULT;
  // CHECK-NEXT: - (void (^ _Nonnull)(BlockReturningBlockWithNoescapeParam _Nonnull))resultHasEscapingParam5 SWIFT_WARN_UNUSED_RESULT;
  @objc func resultHasEscapingParam1() -> (@escaping PlainBlock) -> () { fatalError() }
  @objc func resultHasEscapingParam2() -> (@escaping BlockWithEscapingParam) -> () { fatalError() }
  @objc func resultHasEscapingParam3() -> (@escaping BlockWithNoescapeParam) -> () { fatalError() }
  @objc func resultHasEscapingParam4() -> (@escaping BlockReturningBlockWithEscapingParam) -> () { fatalError() }
  @objc func resultHasEscapingParam5() -> (@escaping BlockReturningBlockWithNoescapeParam) -> () { fatalError() }

}
// CHECK-NEXT: @end
