|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Transitive.swiftmodule -parse-as-library %t/Transitive.swift |
| 4 | +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Direct.swiftmodule -I %t/ -parse-as-library %t/Direct.swift |
| 5 | +// RUN: %target-swift-frontend -typecheck -verify -I %t/ %t/Client.swift -verify-additional-prefix no-member-import- |
| 6 | +// RUN: %target-swift-frontend -typecheck -verify -I %t/ %t/Client.swift -enable-upcoming-feature MemberImportVisibility -verify-additional-prefix member-import- |
| 7 | + |
| 8 | +// REQUIRES: swift_feature_MemberImportVisibility |
| 9 | + |
| 10 | +//--- Transitive.swift |
| 11 | + |
| 12 | +@resultBuilder |
| 13 | +public struct TransitiveIntBuilder { |
| 14 | + public static func buildBlock(_ v: Int) -> Int { |
| 15 | + return v |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +public func transitiveTakesTransitiveBuilder( |
| 20 | + @TransitiveIntBuilder builder: () -> Int |
| 21 | +) { |
| 22 | + _ = builder() |
| 23 | +} |
| 24 | + |
| 25 | +extension Int { |
| 26 | + public static func transitiveTakesTransitiveBuilder( |
| 27 | + @TransitiveIntBuilder builder: () -> Int |
| 28 | + ) { |
| 29 | + _ = builder() |
| 30 | + } |
| 31 | + |
| 32 | + public static func ambiguous( |
| 33 | + @TransitiveIntBuilder transitiveBuilder builder: () -> Int |
| 34 | + ) { |
| 35 | + _ = builder() |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +//--- Direct.swift |
| 40 | + |
| 41 | +import Transitive |
| 42 | + |
| 43 | +@resultBuilder |
| 44 | +public struct DirectIntBuilder { |
| 45 | + public static func buildBlock(_ v: Int) -> Int { |
| 46 | + return v |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +public func directTakesDirectBuilder( |
| 51 | + @DirectIntBuilder builder: () -> Int |
| 52 | +) { |
| 53 | + _ = builder() |
| 54 | +} |
| 55 | + |
| 56 | +public func directTakesTransitiveBuilder( |
| 57 | + @TransitiveIntBuilder builder: () -> Int |
| 58 | +) { |
| 59 | + _ = builder() |
| 60 | +} |
| 61 | + |
| 62 | +extension Int { |
| 63 | + public static func directTakesDirectBuilder( |
| 64 | + @DirectIntBuilder builder: () -> Int |
| 65 | + ) { |
| 66 | + _ = builder() |
| 67 | + } |
| 68 | + |
| 69 | + public static func directTakesTransitiveBuilder( |
| 70 | + @TransitiveIntBuilder builder: () -> Int |
| 71 | + ) { |
| 72 | + _ = builder() |
| 73 | + } |
| 74 | + |
| 75 | + public static func ambiguous( |
| 76 | + @DirectIntBuilder directBuilder builder: () -> Int |
| 77 | + ) { |
| 78 | + _ = builder() |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +//--- Client.swift |
| 83 | + |
| 84 | +import Direct |
| 85 | + |
| 86 | +// expected-member-import-note@-1 4 {{add import of module 'Transitive'}} |
| 87 | + |
| 88 | +transitiveTakesTransitiveBuilder { 1 } // expected-error {{cannot find 'transitiveTakesTransitiveBuilder' in scope}} |
| 89 | +directTakesDirectBuilder { 1 } |
| 90 | +directTakesTransitiveBuilder { 1 } // expected-member-import-error {{static method 'buildBlock' is not available due to missing import of defining module 'Transitive'}} |
| 91 | + |
| 92 | +Int.transitiveTakesTransitiveBuilder { 1 } // expected-member-import-error {{static method 'transitiveTakesTransitiveBuilder(builder:)' is not available due to missing import of defining module 'Transitive'}} |
| 93 | +// expected-member-import-error@-1 {{static method 'buildBlock' is not available due to missing import of defining module 'Transitive'}} |
| 94 | +Int.directTakesDirectBuilder { 1 } |
| 95 | +Int.directTakesTransitiveBuilder { 1 } // expected-member-import-error {{static method 'buildBlock' is not available due to missing import of defining module 'Transitive'}} |
| 96 | +Int.ambiguous { 1 } // expected-no-member-import-error {{ambiguous use of 'ambiguous'}} |
| 97 | +// expected-no-member-import-note@-1 {{use an explicit argument label instead of a trailing closure to call 'ambiguous(transitiveBuilder:)'}} |
| 98 | +// expected-no-member-import-note@-2 {{use an explicit argument label instead of a trailing closure to call 'ambiguous(directBuilder:)'}} |
0 commit comments