Skip to content

[AST] Don’t print internal function labels if they start with '$' #37238

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
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
10 changes: 6 additions & 4 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4857,11 +4857,13 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
PrintNameContext::FunctionParameterExternal);
Printer << ": ";
} else if (Options.AlwaysTryPrintParameterLabels &&
Param.hasInternalLabel()) {
Param.hasInternalLabel() &&
!Param.getInternalLabel().hasDollarPrefix()) {
// We didn't have an external parameter label but were requested to
// always try and print parameter labels. Print The internal label.
// If we have neither an external nor an internal label, only print the
// type.
// always try and print parameter labels.
// If the internal label is a valid internal parameter label (does not
// start with '$'), print the internal label. If we have neither an
// external nor a printable internal label, only print the type.
Printer << "_ ";
Printer.printName(Param.getInternalLabel(),
PrintNameContext::FunctionParameterLocal);
Expand Down
12 changes: 12 additions & 0 deletions test/ModuleInterface/closure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -typecheck %s -emit-module-interface-path %t/main.swiftinterface -enable-library-evolution
// RUN: %FileCheck %s < %t/main.swiftinterface

// CHECK: import Swift

// CHECK: public let MyClosureVar: (Swift.Int) -> Swift.Int
public let MyClosureVar: (Int) -> Int = { $0 }

// CHECK: public var MyOtherClosureVar: (_ x: Swift.Int) -> Swift.Int
public let MyOtherClosureVar: (_ x: Int) -> Int