Skip to content

Commit

Permalink
Merge pull request #7378 from jrose-apple/3.1-TypeLoc-willSet-didSet
Browse files Browse the repository at this point in the history
When setting a willSet/didSet param's type, also set the TypeLoc
  • Loading branch information
tkremenek committed Feb 10, 2017
2 parents abe1fa7 + c869135 commit 41ac6d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Sema/TypeCheckDecl.cpp
Expand Up @@ -4787,6 +4787,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
auto *newValueParam = firstParamPattern->get(0);
newValueParam->setType(valueTy);
newValueParam->setInterfaceType(valueIfaceTy);
newValueParam->getTypeLoc().setType(valueTy);
} else if (FD->isGetter() && FD->isImplicit()) {
FD->getBodyResultTypeLoc().setType(valueIfaceTy, true);
}
Expand Down
37 changes: 37 additions & 0 deletions test/decl/var/properties.swift
Expand Up @@ -1187,3 +1187,40 @@ class r24314506 { // expected-error {{class 'r24314506' has no initializers}}
}


// https://bugs.swift.org/browse/SR-3893
// Generic type is not inferenced from its initial value for properties with
// will/didSet
struct SR3893Box<Foo> {
let value: Foo
}

struct SR3893 {
// Each of these "bad" properties used to produce errors.
var bad: SR3893Box = SR3893Box(value: 0) {
willSet {
print(newValue.value)
}
}

var bad2: SR3893Box = SR3893Box(value: 0) {
willSet(new) {
print(new.value)
}
}

var bad3: SR3893Box = SR3893Box(value: 0) {
didSet {
print(oldValue.value)
}
}

var good: SR3893Box<Int> = SR3893Box(value: 0) {
didSet {
print(oldValue.value)
}
}

var plain: SR3893Box = SR3893Box(value: 0)
}


0 comments on commit 41ac6d6

Please sign in to comment.