Skip to content

Commit 7c5b4d1

Browse files
Merge pull request #30552 from AnthonyLatsis/assoc-coloring
[ASTWalker] Associated type defaults deserve syntax coloring
2 parents aacdd3a + 016d3bb commit 7c5b4d1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
267267
if (doIt(Inherit))
268268
return true;
269269
}
270-
271-
if (auto *ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
270+
271+
if (const auto ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
272+
if (const auto DefaultTy = ATD->getDefaultDefinitionTypeRepr())
273+
if (doIt(DefaultTy))
274+
return true;
275+
272276
if (auto *WhereClause = ATD->getTrailingWhereClause()) {
273277
for (auto &Req: WhereClause->getRequirements()) {
274278
if (doIt(Req))

test/IDE/coloring.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ func foo(n: Float) -> Int {
160160

161161
// CHECK: <kw>protocol</kw> Prot
162162
protocol Prot {
163+
// CHECK: <kw>associatedtype</kw> Assoc1 = <type>Array</type><<type>Never</type>>
164+
associatedtype Assoc1 = Array<Never>
165+
// CHECK: <kw>associatedtype</kw> Assoc2 = <type>Void</type> <kw>where</kw> <type>Assoc2</type>: <type>Equatable</type>
166+
associatedtype Assoc2 = Void where Assoc2: Equatable
167+
// CHECK: <kw>associatedtype</kw> Assoc3: <type>Prot</type>, <type>Prot</type> = <type>Void</type> <kw>where</kw> <type>Assoc3</type>: <type>Prot</type>
168+
associatedtype Assoc3: Prot, Prot = Void where Assoc3: Prot
163169
// CHECK: <kw>typealias</kw> Blarg
164170
typealias Blarg
165171
// CHECK: <kw>func</kw> protMeth(x: <type>Int</type>)

0 commit comments

Comments
 (0)