[SE-0258] Support initial values & explicit initialization arguments.

Allow both explicit initialization and initial values to work together, e.g.,

```
@Clamping(min: 0, max: 255) var red: Int = 127
```

gets initialized as

```
Clamping(initialValue: 127, min: 0, max: 255)
```
This commit is contained in:
Doug Gregor
2019-06-14 01:10:53 -07:00
parent 99b40ba728
commit d35e1eaf72
6 changed files with 97 additions and 72 deletions

View File

@@ -1847,8 +1847,8 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
}
// Get the property wrapper information.
if (!var->allAttachedPropertyWrappersHaveInitialValueInit()) {
assert(!originalInitialValue);
if (!var->allAttachedPropertyWrappersHaveInitialValueInit() &&
!originalInitialValue) {
return PropertyWrapperBackingPropertyInfo(
backingVar, storageVar, nullptr, nullptr, nullptr);
}
@@ -1859,9 +1859,10 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
new (ctx) OpaqueValueExpr(var->getLoc(), var->getType(),
/*isPlaceholder=*/true);
Expr *initializer = buildPropertyWrapperInitialValueCall(
var, storageType, origValue);
typeCheckSynthesizedWrapperInitializer(pbd, backingVar, parentPBD,
initializer);
var, storageType, origValue,
/*ignoreAttributeArgs=*/!originalInitialValue);
typeCheckSynthesizedWrapperInitializer(
pbd, backingVar, parentPBD, initializer);
return PropertyWrapperBackingPropertyInfo(
backingVar, storageVar, originalInitialValue, initializer, origValue);