[AST] NFC: De-boilerplate TupleType "is paren like" checks
Also, make callers be explicit when they're ignoring the field name.
diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h
index c0b7519..d411fc6 100644
--- a/include/swift/AST/Types.h
+++ b/include/swift/AST/Types.h
@@ -1633,6 +1633,16 @@
return static_cast<bool>(Bits.TupleType.HasInOutElement);
}
+ /// Returns true if this tuple has parenthesis semantics.
+ bool hasParenSema(bool allowName = false) const {
+ auto Fields = getElements();
+ if (Fields.size() != 1 || Fields[0].isVararg())
+ return false;
+ if (allowName)
+ return true;
+ return !Fields[0].hasName();
+ }
+
// Implement isa/cast/dyncast/etc.
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::Tuple;
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index ebdabd9..904505b 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -685,7 +685,7 @@
Type TypeBase::getWithoutImmediateLabel() {
Type Ty = this;
if (auto tupleTy = dyn_cast<TupleType>(Ty.getPointer())) {
- if (tupleTy->getNumElements() == 1 && !tupleTy->getElement(0).isVararg())
+ if (tupleTy->hasParenSema(/*allowName*/true))
Ty = tupleTy->getElementType(0);
}
return Ty;
@@ -870,7 +870,7 @@
// Look through argument list tuples.
if (auto tupleTy = type->getAs<TupleType>()) {
- if (tupleTy->getNumElements() == 1 && !tupleTy->getElement(0).isVararg())
+ if (tupleTy->hasParenSema(/*allowName*/true))
type = tupleTy->getElementType(0);
}
diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp
index 6d58ab8..ff5f3a4 100644
--- a/lib/Sema/CSSimplify.cpp
+++ b/lib/Sema/CSSimplify.cpp
@@ -1965,8 +1965,7 @@
// For non-argument tuples, we can do the same conversion but not
// to a tuple with varargs.
if (!type1->is<LValueType>() &&
- ((tuple2->getNumElements() == 1 &&
- !tuple2->getElement(0).isVararg()) ||
+ (tuple2->hasParenSema(/*allowName*/true) ||
(kind >= ConstraintKind::Conversion &&
tuple2->getElementForScalarInit() >= 0 &&
(isArgumentTupleConversion ||
diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp
index 33e8442..84265ee 100644
--- a/lib/Sema/TypeCheckPattern.cpp
+++ b/lib/Sema/TypeCheckPattern.cpp
@@ -973,8 +973,7 @@
if ((options & TypeResolutionFlags::EnumPatternPayload)
&& !isa<TuplePattern>(semantic)) {
if (auto tupleType = type->getAs<TupleType>()) {
- if (tupleType->getNumElements() == 1
- && !tupleType->getElement(0).isVararg()) {
+ if (tupleType->hasParenSema(/*allowName*/true)) {
auto elementTy = tupleType->getElementType(0);
if (coercePatternToType(sub, dc, elementTy, subOptions, resolver))
return true;