Skip to content

Commit 0470b62

Browse files
committed
---
yaml --- r: 348539 b: refs/heads/master c: 5e5c5b1 h: refs/heads/master i: 348537: 389ec26 348535: 3f631f6
1 parent 09dfc6a commit 0470b62

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0291bbfed63409fe258a4b55641f1e40d9c7f918
2+
refs/heads/master: 5e5c5b153d860f899d5bdeb5365a9335ce838543
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,11 +2478,11 @@ namespace {
24782478
}
24792479

24802480
Type visitDefaultArgumentExpr(DefaultArgumentExpr *expr) {
2481-
llvm_unreachable("Already type checked");
2481+
return expr->getType();
24822482
}
24832483

24842484
Type visitCallerDefaultArgumentExpr(CallerDefaultArgumentExpr *expr) {
2485-
llvm_unreachable("Already type checked");
2485+
return expr->getType();
24862486
}
24872487

24882488
Type visitApplyExpr(ApplyExpr *expr) {

trunk/lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,9 @@ ConstraintSystem::getArgumentInfoLocator(ConstraintLocator *locator) {
28802880

28812881
Optional<ConstraintSystem::ArgumentInfo>
28822882
ConstraintSystem::getArgumentInfo(ConstraintLocator *locator) {
2883+
if (!locator)
2884+
return None;
2885+
28832886
if (auto *infoLocator = getArgumentInfoLocator(locator)) {
28842887
auto known = ArgumentInfos.find(infoLocator);
28852888
if (known != ArgumentInfos.end())

trunk/lib/Sema/TypeCheckCaptures.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,12 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
645645
}
646646
}
647647

648+
static bool isLazy(PatternBindingDecl *PBD) {
649+
if (auto var = PBD->getSingleVar())
650+
return var->getAttrs().hasAttribute<LazyAttr>();
651+
return false;
652+
}
653+
648654
void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
649655
auto &ctx = typeDecl->getASTContext();
650656

@@ -669,7 +675,7 @@ void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
669675
/*ObjC=*/false);
670676
init->walk(finder);
671677

672-
if (finder.getDynamicSelfCaptureLoc().isValid()) {
678+
if (finder.getDynamicSelfCaptureLoc().isValid() && !isLazy(PBD)) {
673679
ctx.Diags.diagnose(finder.getDynamicSelfCaptureLoc(),
674680
diag::dynamic_self_stored_property_init);
675681
}

trunk/test/type/self.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,13 @@ class SelfStoredPropertyInit {
253253
static func myValue() -> Int { return 123 }
254254

255255
var value = Self.myValue() // expected-error {{covariant 'Self' type cannot be referenced from a stored property initializer}}
256-
}
256+
}
257+
258+
// rdar://problem/55273931 - erroneously rejecting 'Self' in lazy initializer
259+
class Foo {
260+
static var value: Int = 17
261+
262+
lazy var doubledValue: Int = {
263+
Self.value * 2
264+
}()
265+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -c %s
2+
3+
@propertyWrapper
4+
class OneOf<Value: Equatable> {
5+
var wrappedValue: Value {
6+
get { value }
7+
set { storeIfAllowed(newValue) }
8+
}
9+
10+
private var value: Value
11+
12+
private let allowedValues: [Value]
13+
14+
init(wrappedValue value: Value, _ allowedValues: Value...) {
15+
precondition(allowedValues.contains(value))
16+
self.value = value
17+
self.allowedValues = allowedValues
18+
}
19+
20+
private func storeIfAllowed(_ value: Value) {
21+
guard allowedValues.contains(value) else {
22+
return
23+
}
24+
25+
self.value = value
26+
}
27+
}
28+
29+
struct Test {
30+
@OneOf(4, 8, 15, 16, 23, 42) private var numbers: Int = 4
31+
}
32+
func test() {
33+
_ = Test()
34+
}

0 commit comments

Comments
 (0)