diff --git a/lib/Sema/PlaygroundTransform.cpp b/lib/Sema/PlaygroundTransform.cpp index ecd9294199bd7..a774881f3e8e1 100644 --- a/lib/Sema/PlaygroundTransform.cpp +++ b/lib/Sema/PlaygroundTransform.cpp @@ -575,6 +575,12 @@ class Instrumenter { // log*() functions return a newly-created log expression to be inserted // after or instead of the expression they're looking at. Expr *logVarDecl(VarDecl *VD) { + if (llvm::dyn_cast(TypeCheckDC) && + VD->getNameStr().equals("self")) { + // Don't log "self" in a constructor + return nullptr; + } + return buildLoggerCall( new (Context) DeclRefExpr(ConcreteDeclRef(VD), SourceLoc(), @@ -586,6 +592,13 @@ class Instrumenter { Expr *logDeclRef(DeclRefExpr *DRE) { VarDecl *VD = llvm::cast(DRE->getDecl()); + + if (llvm::dyn_cast(TypeCheckDC) && + VD->getNameStr().equals("self")) { + // Don't log "self" in a constructor + return nullptr; + } + return buildLoggerCall( new (Context) DeclRefExpr(ConcreteDeclRef(VD), SourceLoc(), diff --git a/test/PlaygroundTransform/init.swift b/test/PlaygroundTransform/init.swift new file mode 100644 index 0000000000000..b95792d2872db --- /dev/null +++ b/test/PlaygroundTransform/init.swift @@ -0,0 +1,26 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cp %s %t/main.swift +// RUN: %target-build-swift -Xfrontend -playground -Xfrontend -debugger-support -o %t/main %S/Inputs/PlaygroundsRuntime.swift %t/main.swift +// RUN: %target-run %t/main | FileCheck %s +class B { + init() { + } +} + +class C : B { + var i : Int + var j : Int + override init() { + i = 3 + j = 5 + i + j + } +} +let c = C() +// CHECK: [{{.*}}] $builtin_log_scope_entry +// CHECK-NEXT: [{{.*}}] $builtin_log[='8'] +// CHECK-NEXT: [{{.*}}] $builtin_log_scope_exit +// CHECK-NEXT: [{{.*}}] $builtin_log_scope_entry +// CHECK-NEXT: [{{.*}}] $builtin_log_scope_exit +// CHECK-NEXT: [{{.*}}] $builtin_log[c='main.C']