Skip to content

[Gardening] Normalize the way paren types are stripped in Sema. #5163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,7 @@ struct ASTNodeBase {};
/// Retrieve the ith element type from the resulting tuple type.
auto getOuterElementType = [&](unsigned i) -> Type {
if (!TT) {
if (auto parenTy = dyn_cast<ParenType>(E->getType().getPointer()))
return parenTy->getUnderlyingType();
return E->getType();
return E->getType()->getWithoutParens();
}

return TT->getElementType(i);
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6388,10 +6388,8 @@ bool FailureDiagnosis::visitIdentityExpr(IdentityExpr *E) {

// If we have a paren expr and our contextual type is a ParenType, remove the
// paren expr sugar.
if (isa<ParenExpr>(E) && contextualType)
if (auto *PT = dyn_cast<ParenType>(contextualType.getPointer()))
contextualType = PT->getUnderlyingType();

if (contextualType)
contextualType = contextualType->getWithoutParens();
if (!typeCheckChildIndependently(E->getSubExpr(), contextualType,
CS->getContextualTypePurpose()))
return true;
Expand Down
12 changes: 2 additions & 10 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,14 +699,6 @@ namespace {
return NTD->getHasFailableInits();
}

Type getInnerParenType(const Type &t) {
if (auto parenType = dyn_cast<ParenType>(t.getPointer())) {
return getInnerParenType(parenType->getUnderlyingType());
}

return t;
}

size_t getOperandCount(Type t) {
size_t nOperands = 0;

Expand Down Expand Up @@ -874,8 +866,8 @@ namespace {
auto argTy = expr->getArg()->getType();
auto argTupleTy = argTy->castTo<TupleType>();
auto argTupleExpr = dyn_cast<TupleExpr>(expr->getArg());
Type firstArgTy = getInnerParenType(argTupleTy->getElement(0).getType());
Type secondArgTy = getInnerParenType(argTupleTy->getElement(1).getType());
Type firstArgTy = argTupleTy->getElement(0).getType()->getWithoutParens();
Type secondArgTy = argTupleTy->getElement(1).getType()->getWithoutParens();

// Determine whether the given declaration is favored.
auto isFavoredDecl = [&](ValueDecl *value) -> bool {
Expand Down
8 changes: 1 addition & 7 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2839,13 +2839,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
if (auto fnType =
fnTypeWithSelf->getResult()->getAs<FunctionType>()) {

auto argType = fnType->getInput();

if (auto parenType =
dyn_cast<ParenType>(argType.getPointer())) {
argType = parenType->getUnderlyingType();
}

auto argType = fnType->getInput()->getWithoutParens();
if (argType->isEqual(favoredType))
result.FavoredChoice = result.ViableCandidates.size();
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3924,10 +3924,7 @@ static OmissionTypeName getTypeNameForOmission(Type type) {
}

// Look through parentheses.
if (auto parenTy = dyn_cast<ParenType>(type.getPointer())) {
type = parenTy->getUnderlyingType();
continue;
}
type = type->getWithoutParens();

// Look through optionals.
if (auto optObjectTy = type->getAnyOptionalObjectType()) {
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ static void substituteInputSugarArgumentType(Type argTy, CanType resultTy,

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

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