Skip to content

When setting a willSet/didSet param's type, also set the TypeLoc #7377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2017
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
1 change: 1 addition & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4797,6 +4797,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
Original file line number Diff line number Diff line change
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)
}