File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,10 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
184184 // / opaque return type reprs.
185185 bool hasOpaque ();
186186
187+ // / Returns a Boolean value indicating whether this written type is
188+ // / parenthesized, that is, matches the following grammar: `'(' type ')'`.
189+ bool isParenType () const ;
190+
187191 // / Retrieve the type repr without any parentheses around it.
188192 // /
189193 // / The use of this function must be restricted to contexts where
Original file line number Diff line number Diff line change @@ -109,14 +109,18 @@ bool TypeRepr::hasOpaque() {
109109 findIf ([](TypeRepr *ty) { return isa<OpaqueReturnTypeRepr>(ty); });
110110}
111111
112+ bool TypeRepr::isParenType () const {
113+ auto *tuple = dyn_cast<TupleTypeRepr>(this );
114+ return tuple && tuple->isParenType ();
115+ }
116+
112117TypeRepr *TypeRepr::getWithoutParens () const {
113- auto *repr = const_cast <TypeRepr *>(this );
114- while (auto *tupleRepr = dyn_cast<TupleTypeRepr>(repr)) {
115- if (!tupleRepr->isParenType ())
116- break ;
117- repr = tupleRepr->getElementType (0 );
118+ auto *result = this ;
119+ while (result->isParenType ()) {
120+ result = cast<TupleTypeRepr>(result)->getElementType (0 );
118121 }
119- return repr;
122+
123+ return const_cast <TypeRepr *>(result);
120124}
121125
122126bool TypeRepr::isSimpleUnqualifiedIdentifier (Identifier identifier) const {
You can’t perform that action at this time.
0 commit comments