Skip to content

Commit 82fb5d3

Browse files
committed
Add test for @_requiresConcreteImplementation
1 parent 5948ba1 commit 82fb5d3

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3456,7 +3456,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
34563456
break;
34573457

34583458
case CheckKind::RequiresConcreteImplementation:
3459-
diagnoseOrDefer(requirement, false,
3459+
diagnoseOrDefer(requirement, /*isError=*/true,
34603460
[witness, requirement](NormalProtocolConformance *conformance) {
34613461
auto &diags = witness->getASTContext().Diags;
34623462
SourceLoc diagLoc = getLocForDiagnosingWitness(conformance, witness);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
@_requiresConcreteImplementation
5+
func f(_: Int) -> Bool // expected-note {{requirement 'f' declared here}}
6+
// expected-note@-1 {{overridden declaration is here}}
7+
func f<T: SignedInteger>(_: T) -> Bool
8+
9+
func g(_: Int) -> Bool
10+
}
11+
12+
extension P {
13+
func f<T: SignedInteger>(_ x: T) -> Bool { // expected-note {{'f' declared here}}
14+
return f(Int(x))
15+
}
16+
17+
func g(_ x: Int) -> Bool { // expected-note {{'g' declared here}}
18+
return f(x)
19+
}
20+
}
21+
22+
protocol Q: P {
23+
override func f(_: Int) -> Bool // expected-error {{override of protocol requirement marked '@_requiresConcreteImplementation' should also be marked }}
24+
}
25+
26+
protocol R: P {
27+
@_requiresConcreteImplementation
28+
override func g(_: Int) -> Bool // expected-note {{requirement 'g' declared here}}
29+
}
30+
31+
struct S: P { // expected-error {{type 'S' does not conform to protocol 'P'}}
32+
// expected-error@-1 {{protocol requirement marked '@_requiresConcreteImplementation' cannot be satisfied }}
33+
}
34+
35+
struct T: P, R { // expected-error {{type 'T' does not conform to protocol 'R'}}
36+
// expected-error@-1 {{protocol requirement marked '@_requiresConcreteImplementation' cannot be satisfied }}
37+
func f(_: Int) -> Bool { true }
38+
}
39+
40+
struct U: R {
41+
func f(_: Int) -> Bool { true }
42+
func g(_: Int) -> Bool { false }
43+
}
44+
45+
class C {
46+
@_requiresConcreteImplementation // expected-error {{'@_requiresConcreteImplementation' can only be specified on protocol requirements}}
47+
var x: Int = 42
48+
}

0 commit comments

Comments
 (0)