Repository: apple/swift
File: lib/Sema/TypeCheckPropertyWrapper.cpp (C++)

Code before:
    }
    return nullptr;

  }

  auto subscript = subscripts.front();
  // the subscript must be as accessible as the nominal type.
  if (isDeclNotAsAccessibleAsParent(subscript, nominal)) {
    subscript->diagnose(diag::property_wrapper_type_requirement_not_accessible,
                        subscript->getFormalAccess(),
                        subscript, nominal->getDeclaredType(),
                        nominal->getFormalAccess());
    return nullptr;
  }

  return subscript;
}

/// Validate key path parameter types for an enclosing-self subscript.
static bool validateEnclosingSelfSubscript(SubscriptDecl *subscript) {
  auto *indices = subscript->getIndices();
  if (!indices || indices->size() != 3)
    return false;

  bool isValid = true;
  auto checkKeyPathParam = [&](unsigned index) {
    auto *param = indices->get(index);
    auto paramTy = param->getInterfaceType();
    if (paramTy->is<ErrorType>())
      return;

    if (!paramTy->isWritableKeyPath() && !paramTy->isReferenceWritableKeyPath()) {
      param->diagnose(diag::property_wrapper_enclosing_self_subscript_keypath_type,
                      param->getArgumentName(), paramTy);
      isValid = false;
    }
  };

  checkKeyPathParam(/*wrapped/projected*/ 1);
  checkKeyPathParam(/*storage*/ 2);

  return isValid;
}

PropertyWrapperTypeInfo
PropertyWrapperTypeInfoRequest::evaluate(
    Evaluator &eval, NominalTypeDecl *nominal) const {
  // We must have the @propertyWrapper attribute to continue.
  if (!nominal->getAttrs().hasAttribute<PropertyWrapperAttr>()) {
    return PropertyWrapperTypeInfo();
  }

Review comment (suggestion):
Instead of `isValid` let's give this function a return.

Code after:
    }
    return nullptr;

  }

  auto subscript = subscripts.front();
  // the subscript must be as accessible as the nominal type.
  if (isDeclNotAsAccessibleAsParent(subscript, nominal)) {
    subscript->diagnose(diag::property_wrapper_type_requirement_not_accessible,
                        subscript->getFormalAccess(),
                        subscript, nominal->getDeclaredType(),
                        nominal->getFormalAccess());
    return nullptr;
  }

  return subscript;
}

/// Validate key path parameter types for an enclosing-self subscript.
static bool validateEnclosingSelfSubscript(SubscriptDecl *subscript) {
  auto *indices = subscript->getIndices();
  if (!indices || indices->size() != 3)
    return false;

  auto checkKeyPathParam = [&](unsigned index) -> bool {
    auto *param = indices->get(index);
    auto paramTy = param->getInterfaceType();
    if (paramTy->hasError())
      return true;

    if (!paramTy->isWritableKeyPath() && !paramTy->isReferenceWritableKeyPath()) {
      param->diagnose(diag::property_wrapper_enclosing_self_subscript_keypath_type,
                      param->getArgumentName(), paramTy);
      return false;
    }
    return true;
  };

  bool wrappedOrProjectedOK = checkKeyPathParam(/*wrapped/projected*/ 1);
  bool storageOK = checkKeyPathParam(/*storage*/ 2);
  return wrappedOrProjectedOK && storageOK;
}

PropertyWrapperTypeInfo
PropertyWrapperTypeInfoRequest::evaluate(
    Evaluator &eval, NominalTypeDecl *nominal) const {
  // We must have the @propertyWrapper attribute to continue.
  if (!nominal->getAttrs().hasAttribute<PropertyWrapperAttr>()) {
    return PropertyWrapperTypeInfo();
  }