Skip to content

Commit 7a514c9

Browse files
committed
Sema: Adjust result builder operation lookup for MemberImportVisibility.
To avoid spurious diagnostics about unavailable operations when checking uses of functions that take result builder closures, lookup of result builder operations needs to ignore the restrictions of the `MemberImportVisibility` feature. The result builder transform should simply use the operations that are found and allow later checks to diagnose the use of inaccessible builder operations. Resolves rdar://144100445.
1 parent e056c63 commit 7a514c9

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ ResultBuilderOpSupport TypeChecker::checkBuilderOpSupport(
13261326
dc->lookupQualified(
13271327
builderType, DeclNameRef(fnName),
13281328
builderType->getAnyNominal()->getLoc(),
1329-
NL_QualifiedDefault | NL_ProtocolMembers, foundDecls);
1329+
NL_QualifiedDefault | NL_ProtocolMembers | NL_IgnoreMissingImports,
1330+
foundDecls);
13301331
for (auto decl : foundDecls) {
13311332
if (auto func = dyn_cast<FuncDecl>(decl)) {
13321333
// Function must be static.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

Comments
 (0)