Skip to content

Commit a815de7

Browse files
committed
[Sema] NFC: Add accessor to determine whether a type variable represents an opaque type
1 parent f27369d commit a815de7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ class TypeVariableType::Implementation {
487487
/// expression.
488488
bool isCodeCompletionToken() const;
489489

490+
/// Determine whether this type variable represents an opened opaque type.
491+
bool isOpaqueType() const;
492+
490493
/// Retrieve the representative of the equivalence class to which this
491494
/// type variable belongs.
492495
///

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ bool TypeVariableType::Implementation::isCodeCompletionToken() const {
154154
return locator && locator->directlyAt<CodeCompletionExpr>();
155155
}
156156

157+
bool TypeVariableType::Implementation::isOpaqueType() const {
158+
if (!locator)
159+
return false;
160+
161+
auto GP = locator->getLastElementAs<LocatorPathElt::GenericParameter>();
162+
if (!GP)
163+
return false;
164+
165+
if (auto *GPT = GP->getType()->getAs<GenericTypeParamType>()) {
166+
auto *decl = GPT->getDecl();
167+
return decl && decl->isOpaqueType();
168+
}
169+
170+
return false;
171+
}
172+
157173
void *operator new(size_t bytes, ConstraintSystem& cs,
158174
size_t alignment) {
159175
return cs.getAllocator().Allocate(bytes, alignment);

0 commit comments

Comments
 (0)