Skip to content

Commit

Permalink
Merge pull request #25821 from DougGregor/property-wrappers-multifile…
Browse files Browse the repository at this point in the history
…-rdar51725203-5.1
  • Loading branch information
swift-ci committed Jun 27, 2019
2 parents 8a49ba7 + 0fc3d98 commit 9e2dc8d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,9 @@ static VarDecl *synthesizePropertyWrapperStorageWrapperProperty(
Identifier name = ctx.getIdentifier(nameBuf);

// Determine the type of the property.
if (!wrapperVar->hasInterfaceType()) {
static_cast<TypeChecker &>(*ctx.getLazyResolver()).validateDecl(wrapperVar);
}
Type propertyType = wrapperType->getTypeOfMember(
var->getModuleContext(), wrapperVar,
wrapperVar->getValueInterfaceType());
Expand Down
19 changes: 19 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5506,6 +5506,25 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
if (!evaluateTargetConformanceTo(decodableProto))
(void)evaluateTargetConformanceTo(encodableProto);
}

if ((baseName.getIdentifier().str().startswith("$") ||
baseName.getIdentifier().str().startswith("_")) &&
baseName.getIdentifier().str().size() > 1) {
// $- and _-prefixed variables can be generated by properties that have
// attached property wrappers.
auto originalPropertyName =
Context.getIdentifier(baseName.getIdentifier().str().substr(1));
for (auto member : target->lookupDirect(originalPropertyName)) {
if (auto var = dyn_cast<VarDecl>(member)) {
if (var->hasAttachedPropertyWrapper()) {
auto sourceFile = var->getDeclContext()->getParentSourceFile();
if (sourceFile && sourceFile->Kind != SourceFileKind::Interface)
(void)var->getPropertyWrapperBackingPropertyInfo();
}
}
}
}

} else {
auto argumentNames = member.getArgumentNames();
if (member.isCompoundName() && argumentNames.size() != 1)
Expand Down
23 changes: 23 additions & 0 deletions test/multifile/Inputs/rdar51725203.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@propertyWrapper
struct Wrapper<Value> {
var wrappedValue: Value

var projectedValue: Wrapper<Value> {
get { self }
set { self = newValue }
}

init(initialValue: Value) {
wrappedValue = initialValue
}
}

struct StructModel {
@Wrapper var foo: Int
@Wrapper var bar: Int // expected-note{{'_bar' declared here}}
}

class ClassModel {
@Wrapper var foo = 17
@Wrapper var bar = 17 // expected-note{{'_bar' declared here}}
}
9 changes: 9 additions & 0 deletions test/multifile/property-wrappers-rdar51725203.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -typecheck -verify -primary-file %s %S/Inputs/rdar51725203.swift

func test(sm: StructModel, cm: ClassModel) {
_ = sm.$foo
_ = cm.$foo

_ = sm._bar // expected-error{{'_bar' is inaccessible due to 'private' protection level}}
_ = cm._bar // expected-error{{'_bar' is inaccessible due to 'private' protection level}}
}

0 comments on commit 9e2dc8d

Please sign in to comment.