Skip to content

[ASTWalker] Associated type defaults deserve syntax coloring #30552

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
Mar 21, 2020
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
8 changes: 6 additions & 2 deletions lib/AST/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
if (doIt(Inherit))
return true;
}

if (auto *ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {

if (const auto ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
if (const auto DefaultTy = ATD->getDefaultDefinitionTypeRepr())
if (doIt(DefaultTy))
return true;

if (auto *WhereClause = ATD->getTrailingWhereClause()) {
for (auto &Req: WhereClause->getRequirements()) {
if (doIt(Req))
Expand Down
6 changes: 6 additions & 0 deletions test/IDE/coloring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func foo(n: Float) -> Int {

// CHECK: <kw>protocol</kw> Prot
protocol Prot {
// CHECK: <kw>associatedtype</kw> Assoc1 = <type>Array</type><<type>Never</type>>
associatedtype Assoc1 = Array<Never>
// CHECK: <kw>associatedtype</kw> Assoc2 = <type>Void</type> <kw>where</kw> <type>Assoc2</type>: <type>Equatable</type>
associatedtype Assoc2 = Void where Assoc2: Equatable
// CHECK: <kw>associatedtype</kw> Assoc3: <type>Prot</type>, <type>Prot</type> = <type>Void</type> <kw>where</kw> <type>Assoc3</type>: <type>Prot</type>
associatedtype Assoc3: Prot, Prot = Void where Assoc3: Prot
// CHECK: <kw>typealias</kw> Blarg
typealias Blarg
// CHECK: <kw>func</kw> protMeth(x: <type>Int</type>)
Expand Down