Skip to content

Commit a6346f8

Browse files
authored
Merge pull request #37239 from ahoppen/pr-5.5/dont-print-dollar-internal-labels
[5.5][AST] Don’t print internal function labels if they start with '$'
2 parents 3a2015f + 229275a commit a6346f8

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
@@ -4894,11 +4894,13 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
48944894
PrintNameContext::FunctionParameterExternal);
48954895
Printer << ": ";
48964896
} else if (Options.AlwaysTryPrintParameterLabels &&
4897-
Param.hasInternalLabel()) {
4897+
Param.hasInternalLabel() &&
4898+
!Param.getInternalLabel().hasDollarPrefix()) {
48984899
// We didn't have an external parameter label but were requested to
4899-
// always try and print parameter labels. Print The internal label.
4900-
// If we have neither an external nor an internal label, only print the
4901-
// type.
4900+
// always try and print parameter labels.
4901+
// If the internal label is a valid internal parameter label (does not
4902+
// start with '$'), print the internal label. If we have neither an
4903+
// external nor a printable internal label, only print the type.
49024904
Printer << "_ ";
49034905
Printer.printName(Param.getInternalLabel(),
49044906
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)