File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -339,7 +339,12 @@ class Instrumenter : InstrumenterBase {
339
339
if (auto *FD = dyn_cast<FuncDecl>(D)) {
340
340
if (BraceStmt *B = FD->getTypecheckedBody ()) {
341
341
const ParameterList *PL = FD->getParameters ();
342
+
343
+ // Use FD's DeclContext as TypeCheckDC for transforms in func body
344
+ // then swap back TypeCheckDC at end of scope.
345
+ llvm::SaveAndRestore<DeclContext *> localDC (TypeCheckDC, FD);
342
346
BraceStmt *NB = transformBraceStmt (B, PL);
347
+
343
348
// Since it would look strange going straight to the first line in a
344
349
// function body, we throw in a before/after pointing at the function
345
350
// decl at the start of the transformed body
Original file line number Diff line number Diff line change @@ -312,6 +312,11 @@ class Instrumenter : InstrumenterBase {
312
312
if (BraceStmt *B = FD->getTypecheckedBody ()) {
313
313
const ParameterList *PL = FD->getParameters ();
314
314
TargetKindSetter TKS (BracePairs, BracePair::TargetKinds::Return);
315
+
316
+ // Use FD's DeclContext as TypeCheckDC for transforms in func body
317
+ // then swap back TypeCheckDC at end of scope.
318
+ llvm::SaveAndRestore<DeclContext *> localDC (TypeCheckDC, FD);
319
+
315
320
BraceStmt *NB = transformBraceStmt (B, PL);
316
321
if (NB != B) {
317
322
FD->setBody (NB, AbstractFunctionDecl::BodyKind::TypeChecked);
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+
3
+ // Build PlaygroundSupport module
4
+ // 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
5
+
6
+ // RUN: %target-build-swift -swift-version 5 -emit-module -Xfrontend -playground -I=%t %s
7
+ // RUN: %target-build-swift -swift-version 6 -emit-module -Xfrontend -playground -I=%t %s
8
+
9
+ // RUN: %target-build-swift -swift-version 5 -emit-module -Xfrontend -playground -Xfrontend -pc-macro -I=%t %s
10
+ // RUN: %target-build-swift -swift-version 6 -emit-module -Xfrontend -playground -Xfrontend -pc-macro -I=%t %s
11
+
12
+ // REQUIRES: executable_test
13
+
14
+ import PlaygroundSupport
15
+
16
+ func test1( ) {
17
+ func buildBlock< Content> ( content: Content ) {
18
+ content
19
+ }
20
+ }
21
+
22
+ func test2( ) {
23
+ func buildBlock< Content> ( content: Content ) -> Content {
24
+ content
25
+ return content
26
+ }
27
+ }
28
+
29
+ func test3< Content> ( _ content: Content ) {
30
+ func buildBlock< Content2> ( _ content2: Content2 ) -> Content2 {
31
+ return content2
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments