Skip to content

Commit 7ebdb8e

Browse files
committed
[ASTPrinter] Fix expression printing for metatype access
And fix operators not printing when we can't get a `MemberOperatorRef`.
1 parent c78674f commit 7ebdb8e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,12 @@ void PrintAST::visitLoadExpr(LoadExpr *expr) {
41514151
}
41524152

41534153
void PrintAST::visitTypeExpr(TypeExpr *expr) {
4154-
printType(expr->getType());
4154+
if (auto metaType = expr->getType()->castTo<AnyMetatypeType>()) {
4155+
// Don't print `.Type` for an expr.
4156+
printType(metaType->getInstanceType());
4157+
} else {
4158+
printType(expr->getType());
4159+
}
41554160
}
41564161

41574162
void PrintAST::visitArrayExpr(ArrayExpr *expr) {
@@ -4234,6 +4239,8 @@ void PrintAST::visitBinaryExpr(BinaryExpr *expr) {
42344239
Printer << " ";
42354240
if (auto operatorRef = expr->getFn()->getMemberOperatorRef()) {
42364241
Printer << operatorRef->getDecl()->getBaseName();
4242+
} else if (auto *operatorRef = dyn_cast<DeclRefExpr>(expr->getFn())) {
4243+
Printer << operatorRef->getDecl()->getBaseName();
42374244
}
42384245
Printer << " ";
42394246
visit(expr->getRHS());

test/expr/print/callexpr.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ test(a: 0, b: 0, c: 0)
88
// CHECK: test(a: 0)
99
// CHECK: test(a: 0, b: 0)
1010
// CHECK: test(a: 0, b: 0, c: 0)
11+
12+
class Constants { static var myConst = 0 }
13+
func test(foo: Int) { }
14+
// CHECK-LABEL: test(foo: Constants.myConst)
15+
test(foo: Constants.myConst)

0 commit comments

Comments
 (0)