Skip to content

Commit 599cbb3

Browse files
committed
---
yaml --- r: 323551 b: refs/heads/tensorflow-next c: 9c0a348 h: refs/heads/master i: 323549: 69b12d0 323547: f9138d8 323543: f6ff6f7 323535: abb8172 323519: b81473b
1 parent 4eeb687 commit 599cbb3

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: 141b5e011ca8967398a51833d887075da84aeea1
1464+
refs/heads/tensorflow-next: 9c0a3483433e312f21601ce9ff9b2a034cf8d29e

branches/tensorflow-next/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;

branches/tensorflow-next/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+
}

branches/tensorflow-next/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)