Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,9 @@ static FuncDecl *findReplacedAccessor(DeclName replacedVarName,
Type replacementStorageType = getDynamicComparisonType(replacementStorage);
results.erase(std::remove_if(results.begin(), results.end(),
[&](ValueDecl *result) {
// Protocol requirements are not replaceable.
if (isa<ProtocolDecl>(result->getDeclContext()))
return true;
// Check for static/instance mismatch.
if (result->isStatic() != replacementStorage->isStatic())
return true;
Expand Down Expand Up @@ -2247,9 +2250,13 @@ findReplacedFunction(DeclName replacedFunctionName,
lookupReplacedDecl(replacedFunctionName, attr, replacement, results);

for (auto *result : results) {
// Protocol requirements are not replaceable.
if (isa<ProtocolDecl>(result->getDeclContext()))
continue;
// Check for static/instance mismatch.
if (result->isStatic() != replacement->isStatic())
continue;

if (TC)
TC->validateDecl(result);
TypeMatchOptions matchMode = TypeMatchFlags::AllowABICompatible;
Expand Down
20 changes: 20 additions & 0 deletions test/attr/Inputs/dynamicReplacementC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,23 @@ public class K {
public convenience init(c : Int) { self.init(i : c) }
public final func finalFunction() {}
}


public protocol P {
var v: Int { get }
subscript(i: Int) -> Int { get }
func f()
}

extension P {
public var v: Int { return 0 }

public subscript(i: Int) -> Int {
get {
return 0
}
}

public func f() {
}
}
18 changes: 18 additions & 0 deletions test/attr/dynamicReplacement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ extension undeclared { // expected-error{{use of undeclared type 'undeclared'}}
@_dynamicReplacement(for: func) // expected-error{{replaced function 'func' could not be found}}
func func2() -> Int { return 2 }
}

extension P {
@_dynamicReplacement(for: v)
var replacement_v : Int {
return 1
}

@_dynamicReplacement(for: subscript(_:))
subscript(y y: Int) -> Int {
get {
return 1
}
}

@_dynamicReplacement(for: f())
func replacement_f() {
}
}