Skip to content

Commit 7462a62

Browse files
authored
Merge pull request #37238 from ahoppen/pr/dont-print-dollar-internal-labels
[AST] Don’t print internal function labels if they start with '$'
2 parents e835b77 + 66e416b commit 7462a62

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,11 +4869,13 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
48694869
PrintNameContext::FunctionParameterExternal);
48704870
Printer << ": ";
48714871
} else if (Options.AlwaysTryPrintParameterLabels &&
4872-
Param.hasInternalLabel()) {
4872+
Param.hasInternalLabel() &&
4873+
!Param.getInternalLabel().hasDollarPrefix()) {
48734874
// We didn't have an external parameter label but were requested to
4874-
// always try and print parameter labels. Print The internal label.
4875-
// If we have neither an external nor an internal label, only print the
4876-
// type.
4875+
// always try and print parameter labels.
4876+
// If the internal label is a valid internal parameter label (does not
4877+
// start with '$'), print the internal label. If we have neither an
4878+
// external nor a printable internal label, only print the type.
48774879
Printer << "_ ";
48784880
Printer.printName(Param.getInternalLabel(),
48794881
PrintNameContext::FunctionParameterLocal);

test/ModuleInterface/closure.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
4+
// RUN: %FileCheck %s < %t/main.swiftinterface
5+
6+
// CHECK: import Swift
7+
8+
// CHECK: public let MyClosureVar: (Swift.Int) -> Swift.Int
9+
public let MyClosureVar: (Int) -> Int = { $0 }
10+
11+
// CHECK: public var MyOtherClosureVar: (_ x: Swift.Int) -> Swift.Int
12+
public let MyOtherClosureVar: (_ x: Int) -> Int

0 commit comments

Comments
 (0)