Skip to content

Commit 31dc11c

Browse files
authored
Merge pull request #76796 from swiftlang/eng/chrismiles/fix-print-instrumenting-for-language-mode-6
Fix instrumenting print and debugPrint for Swift 6.
2 parents 57ede9c + 2e675c9 commit 31dc11c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,14 @@ class Instrumenter : InstrumenterBase {
461461
}
462462
} else if (auto *AE = dyn_cast<ApplyExpr>(E)) {
463463
bool Handled = false;
464-
if (auto *DRE = dyn_cast<DeclRefExpr>(AE->getFn())) {
464+
DeclRefExpr *DRE = nullptr;
465+
// With Swift 6 the print() function decl is a sub expression
466+
// of a function conversion expression.
467+
if (auto *FCE = dyn_cast<FunctionConversionExpr>(AE->getFn()))
468+
DRE = dyn_cast<DeclRefExpr>(FCE->getSubExpr());
469+
else
470+
DRE = dyn_cast<DeclRefExpr>(AE->getFn());
471+
if (DRE) {
465472
auto *FnD = dyn_cast<AbstractFunctionDecl>(DRE->getDecl());
466473
if (FnD && FnD->getModuleContext() == Context.TheStdlibModule) {
467474
DeclBaseName FnName = FnD->getBaseName();

test/PlaygroundTransform/print.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
// RUN: %empty-directory(%t)
22
// RUN: cp %s %t/main.swift
33
// RUN: %target-build-swift -whole-module-optimization -module-name PlaygroundSupport -emit-module-path %t/PlaygroundSupport.swiftmodule -parse-as-library -c -o %t/PlaygroundSupport.o %S/Inputs/SilentPCMacroRuntime.swift %S/Inputs/PlaygroundsRuntime.swift
4+
//
5+
// Default Swift version
46
// RUN: %target-build-swift -Xfrontend -playground -o %t/main -I=%t %t/PlaygroundSupport.o %t/main.swift
57
// RUN: %target-codesign %t/main
68
// RUN: %target-run %t/main | %FileCheck %s
79
// RUN: %target-build-swift -Xfrontend -pc-macro -Xfrontend -playground -o %t/main2 -I=%t %t/PlaygroundSupport.o %t/main.swift
810
// RUN: %target-codesign %t/main2
911
// RUN: %target-run %t/main2 | %FileCheck %s
12+
//
13+
// Swift version 6
14+
// RUN: %target-build-swift -swift-version 6 -Xfrontend -playground -o %t/main3 -I=%t %t/PlaygroundSupport.o %t/main.swift
15+
// RUN: %target-codesign %t/main3
16+
// RUN: %target-run %t/main3 | %FileCheck %s
17+
// RUN: %target-build-swift -swift-version 6 -Xfrontend -pc-macro -Xfrontend -playground -o %t/main4 -I=%t %t/PlaygroundSupport.o %t/main.swift
18+
// RUN: %target-codesign %t/main4
19+
// RUN: %target-run %t/main4 | %FileCheck %s
1020
// REQUIRES: executable_test
1121

1222
import PlaygroundSupport

0 commit comments

Comments
 (0)