Skip to content

Commit 7ba11dd

Browse files
authored
Merge pull request #5163 from CodaFi/the-paren-trap
[Gardening] Normalize the way paren types are stripped in Sema.
2 parents 1dc300f + f59d5cb commit 7ba11dd

File tree

6 files changed

+8
-30
lines changed

6 files changed

+8
-30
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,7 @@ struct ASTNodeBase {};
14871487
/// Retrieve the ith element type from the resulting tuple type.
14881488
auto getOuterElementType = [&](unsigned i) -> Type {
14891489
if (!TT) {
1490-
if (auto parenTy = dyn_cast<ParenType>(E->getType().getPointer()))
1491-
return parenTy->getUnderlyingType();
1492-
return E->getType();
1490+
return E->getType()->getWithoutParens();
14931491
}
14941492

14951493
return TT->getElementType(i);

lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6388,10 +6388,8 @@ bool FailureDiagnosis::visitIdentityExpr(IdentityExpr *E) {
63886388

63896389
// If we have a paren expr and our contextual type is a ParenType, remove the
63906390
// paren expr sugar.
6391-
if (isa<ParenExpr>(E) && contextualType)
6392-
if (auto *PT = dyn_cast<ParenType>(contextualType.getPointer()))
6393-
contextualType = PT->getUnderlyingType();
6394-
6391+
if (contextualType)
6392+
contextualType = contextualType->getWithoutParens();
63956393
if (!typeCheckChildIndependently(E->getSubExpr(), contextualType,
63966394
CS->getContextualTypePurpose()))
63976395
return true;

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -699,14 +699,6 @@ namespace {
699699
return NTD->getHasFailableInits();
700700
}
701701

702-
Type getInnerParenType(const Type &t) {
703-
if (auto parenType = dyn_cast<ParenType>(t.getPointer())) {
704-
return getInnerParenType(parenType->getUnderlyingType());
705-
}
706-
707-
return t;
708-
}
709-
710702
size_t getOperandCount(Type t) {
711703
size_t nOperands = 0;
712704

@@ -874,8 +866,8 @@ namespace {
874866
auto argTy = expr->getArg()->getType();
875867
auto argTupleTy = argTy->castTo<TupleType>();
876868
auto argTupleExpr = dyn_cast<TupleExpr>(expr->getArg());
877-
Type firstArgTy = getInnerParenType(argTupleTy->getElement(0).getType());
878-
Type secondArgTy = getInnerParenType(argTupleTy->getElement(1).getType());
869+
Type firstArgTy = argTupleTy->getElement(0).getType()->getWithoutParens();
870+
Type secondArgTy = argTupleTy->getElement(1).getType()->getWithoutParens();
879871

880872
// Determine whether the given declaration is favored.
881873
auto isFavoredDecl = [&](ValueDecl *value) -> bool {

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,13 +2839,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
28392839
if (auto fnType =
28402840
fnTypeWithSelf->getResult()->getAs<FunctionType>()) {
28412841

2842-
auto argType = fnType->getInput();
2843-
2844-
if (auto parenType =
2845-
dyn_cast<ParenType>(argType.getPointer())) {
2846-
argType = parenType->getUnderlyingType();
2847-
}
2848-
2842+
auto argType = fnType->getInput()->getWithoutParens();
28492843
if (argType->isEqual(favoredType))
28502844
result.FavoredChoice = result.ViableCandidates.size();
28512845
}

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,10 +3924,7 @@ static OmissionTypeName getTypeNameForOmission(Type type) {
39243924
}
39253925

39263926
// Look through parentheses.
3927-
if (auto parenTy = dyn_cast<ParenType>(type.getPointer())) {
3928-
type = parenTy->getUnderlyingType();
3929-
continue;
3930-
}
3927+
type = type->getWithoutParens();
39313928

39323929
// Look through optionals.
39333930
if (auto optObjectTy = type->getAnyOptionalObjectType()) {

lib/Sema/TypeCheckExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ static void substituteInputSugarArgumentType(Type argTy, CanType resultTy,
5454

5555
// If this type is parenthesized, remove the parens. We don't want to
5656
// propagate parens from arguments to the result type.
57-
if (auto *PT = dyn_cast<ParenType>(argTy.getPointer()))
58-
argTy = PT->getUnderlyingType();
57+
argTy = argTy->getWithoutParens();
5958

6059
// If this is the first match against the sugar type we found, use it.
6160
if (!resultSugarTy) {

0 commit comments

Comments
 (0)