Skip to content

Commit db6801b

Browse files
committed
[Diagnostics] Add getRawType which allows to retrieve type associated with ASTNode
This is useful when diagnostic needs to check something about type variables involved in a particular type e.g. whether type variable has been defaulted.
1 parent ee6c228 commit db6801b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ ASTNode FailureDiagnostic::getAnchor() const {
7373
}
7474

7575
Type FailureDiagnostic::getType(ASTNode node, bool wantRValue) const {
76-
return resolveType(S.getType(node), /*reconstituteSugar=*/false, wantRValue);
76+
return resolveType(getRawType(node), /*reconstituteSugar=*/false, wantRValue);
77+
}
78+
79+
Type FailureDiagnostic::getRawType(ASTNode node) const {
80+
return S.getType(node);
7781
}
7882

7983
template <typename... ArgTypes>
@@ -3420,7 +3424,8 @@ bool MissingMemberFailure::diagnoseInLiteralCollectionContext() const {
34203424
return false;
34213425
}
34223426

3423-
if (auto *defaultableVar = getType(parentExpr)->getAs<TypeVariableType>()) {
3427+
if (auto *defaultableVar =
3428+
getRawType(parentExpr)->getAs<TypeVariableType>()) {
34243429
if (solution.DefaultedConstraints.count(
34253430
defaultableVar->getImpl().getLocator()) != 0) {
34263431
emitDiagnostic(diag::unresolved_member_no_inference, getName());

lib/Sema/CSDiagnostics.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class FailureDiagnostic {
8686

8787
Type getType(ASTNode node, bool wantRValue = true) const;
8888

89+
/// Get type associated with a given ASTNode without resolving it,
90+
/// which means that returned type would have type variables.
91+
Type getRawType(ASTNode node) const;
92+
8993
/// Resolve type variables present in the raw type, if any.
9094
Type resolveType(Type rawType, bool reconstituteSugar = false,
9195
bool wantRValue = true) const {
@@ -205,7 +209,7 @@ class FailureDiagnostic {
205209

206210
bool isCollectionType(Type type) const {
207211
auto &cs = getConstraintSystem();
208-
return bool(cs.isCollectionType(type));
212+
return cs.isCollectionType(type);
209213
}
210214

211215
bool isArrayType(Type type) const {

0 commit comments

Comments
 (0)