Skip to content

Commit 9c0a348

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 141b5e0 + 326da87 commit 9c0a348

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,9 @@ static FuncDecl *findReplacedAccessor(DeclName replacedVarName,
21632163
Type replacementStorageType = getDynamicComparisonType(replacementStorage);
21642164
results.erase(std::remove_if(results.begin(), results.end(),
21652165
[&](ValueDecl *result) {
2166+
// Protocol requirements are not replaceable.
2167+
if (isa<ProtocolDecl>(result->getDeclContext()))
2168+
return true;
21662169
// Check for static/instance mismatch.
21672170
if (result->isStatic() != replacementStorage->isStatic())
21682171
return true;
@@ -2244,9 +2247,13 @@ findReplacedFunction(DeclName replacedFunctionName,
22442247
lookupReplacedDecl(replacedFunctionName, attr, replacement, results);
22452248

22462249
for (auto *result : results) {
2250+
// Protocol requirements are not replaceable.
2251+
if (isa<ProtocolDecl>(result->getDeclContext()))
2252+
continue;
22472253
// Check for static/instance mismatch.
22482254
if (result->isStatic() != replacement->isStatic())
22492255
continue;
2256+
22502257
if (TC)
22512258
TC->validateDecl(result);
22522259
TypeMatchOptions matchMode = TypeMatchFlags::AllowABICompatible;

test/attr/Inputs/dynamicReplacementC.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,23 @@ public class K {
1313
public convenience init(c : Int) { self.init(i : c) }
1414
public final func finalFunction() {}
1515
}
16+
17+
18+
public protocol P {
19+
var v: Int { get }
20+
subscript(i: Int) -> Int { get }
21+
func f()
22+
}
23+
24+
extension P {
25+
public var v: Int { return 0 }
26+
27+
public subscript(i: Int) -> Int {
28+
get {
29+
return 0
30+
}
31+
}
32+
33+
public func f() {
34+
}
35+
}

test/attr/dynamicReplacement.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ extension undeclared { // expected-error{{use of undeclared type 'undeclared'}}
5757
@_dynamicReplacement(for: func) // expected-error{{replaced function 'func' could not be found}}
5858
func func2() -> Int { return 2 }
5959
}
60+
61+
extension P {
62+
@_dynamicReplacement(for: v)
63+
var replacement_v : Int {
64+
return 1
65+
}
66+
67+
@_dynamicReplacement(for: subscript(_:))
68+
subscript(y y: Int) -> Int {
69+
get {
70+
return 1
71+
}
72+
}
73+
74+
@_dynamicReplacement(for: f())
75+
func replacement_f() {
76+
}
77+
}

0 commit comments

Comments
 (0)