Skip to content

Commit 8fdfbaa

Browse files
committed
[Playground transform] Retain ! expressions when logging variables.
When a force-value expression (!) is encountered while logging variables, retain the force-value expression rather than dropping it. This allows logging involving implicitly unwrapped optionals. Fixes rdar://problem/56098581.
1 parent 34a883d commit 8fdfbaa

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/Sema/PlaygroundTransform.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,16 @@ class Instrumenter : InstrumenterBase {
320320
}
321321
case ExprKind::Load:
322322
return digForVariable(cast<LoadExpr>(E)->getSubExpr());
323-
case ExprKind::ForceValue:
324-
return digForVariable(cast<ForceValueExpr>(E)->getSubExpr());
323+
case ExprKind::ForceValue: {
324+
std::pair<Added<Expr *>, ValueDecl *> BaseVariable =
325+
digForVariable(cast<ForceValueExpr>(E)->getSubExpr());
326+
if (!*BaseVariable.first || !BaseVariable.second)
327+
return std::make_pair(nullptr, nullptr);
328+
329+
Added<Expr *> Forced(
330+
new (Context) ForceValueExpr(*BaseVariable.first, SourceLoc()));
331+
return std::make_pair(Forced, BaseVariable.second);
332+
}
325333
case ExprKind::InOut:
326334
return digForVariable(cast<InOutExpr>(E)->getSubExpr());
327335
}

test/PlaygroundTransform/iuo.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-build-swift -force-single-frontend-invocation -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+
// RUN: %target-build-swift -Xfrontend -playground -o %t/main -I=%t %t/PlaygroundSupport.o %t/main.swift
5+
6+
import PlaygroundSupport
7+
8+
class Layer {
9+
var value: Double = 0
10+
}
11+
12+
class Outer {
13+
let layer: Layer! = Layer()
14+
}
15+
16+
class Enclosing {
17+
var outer: Outer! = Outer()
18+
19+
func test() {
20+
// Ensure that this doesn't crash
21+
outer.layer.value = 3.14159
22+
}
23+
}
24+
25+
Enclosing().test()

0 commit comments

Comments
 (0)