mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to treat potentially unavailable declarations as if they had optional types. For the moment, this is only implemented for global variables. The high-level approach is to (1) record the potential unavailability of a declaration reference in the overload choice during constraint generation; (2) treat the declaration as if it had an optional type during overload resolution (this is similar to how optional protocol members are treated); and (3) add an implicit conversion (UnavailableToOptionalExpr) during constraint application to represent the run-time availability check and optional injection. This patch does not implement SILGen for UnavailableToOptionalExpr. Swift SVN r22245
This commit is contained in:
@@ -3450,6 +3450,11 @@ Type ConstraintSystem::getBaseTypeForArrayType(TypeBase *type) {
|
||||
llvm_unreachable("attempted to extract a base type from a non-array type");
|
||||
}
|
||||
|
||||
Type ConstraintSystem::getTypeWhenUnavailable(Type declType) {
|
||||
// Drop lvalue-ness and make optional.
|
||||
return OptionalType::get(declType->getRValueType());
|
||||
}
|
||||
|
||||
static Type getBaseTypeForPointer(ConstraintSystem &cs, TypeBase *type) {
|
||||
auto bgt = type->castTo<BoundGenericType>();
|
||||
assert((bgt->getDecl() == cs.getASTContext().getUnsafeMutablePointerDecl()
|
||||
|
||||
Reference in New Issue
Block a user