From ec67ca07b08eebd96fb2f78c2b42bd58d28c2b2e Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 14 Dec 2018 21:16:44 -0500 Subject: [PATCH 1/3] Add test case for https://bugs.swift.org/browse/SR-6739 --- test/SILGen/default_arguments.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/SILGen/default_arguments.swift b/test/SILGen/default_arguments.swift index a795fa0e7e0d4..b3d86d246df7a 100644 --- a/test/SILGen/default_arguments.swift +++ b/test/SILGen/default_arguments.swift @@ -367,3 +367,13 @@ func callThem() throws { defaultEscaping() autoclosureDefaultEscaping() } + +func tupleDefaultArg(x: (Int, Int) = (1, 2)) {} + +// CHECK-LABEL: sil hidden @$s17default_arguments19callTupleDefaultArgyyF : $@convention(thin) () -> () +// CHECK: function_ref @$s17default_arguments15tupleDefaultArg1xySi_Sit_tFfA_ : $@convention(thin) () -> (Int, Int) +// CHECK: function_ref @$s17default_arguments15tupleDefaultArg1xySi_Sit_tF : $@convention(thin) (Int, Int) -> () +// CHECK: return +func callTupleDefaultArg() { + tupleDefaultArg() +} \ No newline at end of file From 2c4a23c7a008d8e987960f5000bdb3512e8f5a17 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 14 Dec 2018 21:20:37 -0500 Subject: [PATCH 2/3] Add test case for https://bugs.swift.org/browse/SR-7771 --- test/SILGen/default_arguments.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/SILGen/default_arguments.swift b/test/SILGen/default_arguments.swift index b3d86d246df7a..48bfaabe90c26 100644 --- a/test/SILGen/default_arguments.swift +++ b/test/SILGen/default_arguments.swift @@ -376,4 +376,10 @@ func tupleDefaultArg(x: (Int, Int) = (1, 2)) {} // CHECK: return func callTupleDefaultArg() { tupleDefaultArg() -} \ No newline at end of file +} + +// FIXME: Should this be banned? +func stupidGames(x: Int = 3) -> Int { + return x +} +stupidGames(x:)() \ No newline at end of file From 98659c697fcc0cdeab1f561a68d5ae83317bc66a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 14 Dec 2018 21:32:06 -0500 Subject: [PATCH 3/3] SILGen: Remove over-eager assertions in assignment lowering We already assert that each element of the tuple is an lvalue; asserting that the tuple itself has an lvalue or is Void is incorrect because the tuple might have zero non-tuple elements recursively but itself not be Void, eg ((), ()). Fixes . --- lib/SILGen/SILGenExpr.cpp | 4 ---- test/SILGen/assignment.swift | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index 1700891281a2f..2cc12d0c46caf 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -4283,9 +4283,6 @@ namespace { // If the destination is a tuple, recursively destructure. void visitTupleExpr(TupleExpr *E) { - auto *TTy = E->getType()->castTo(); - assert(TTy->hasLValueType() || TTy->isVoid()); - (void)TTy; for (auto &elt : E->getElements()) { visit(elt); } @@ -4398,7 +4395,6 @@ static void emitSimpleAssignment(SILGenFunction &SGF, SILLocation loc, // Handle tuple destinations by destructuring them if present. CanType destType = dest->getType()->getCanonicalType(); - assert(!destType->isMaterializable() || destType->isVoid()); // But avoid this in the common case. if (!isa(destType)) { diff --git a/test/SILGen/assignment.swift b/test/SILGen/assignment.swift index efd002938a612..876515654bf5c 100644 --- a/test/SILGen/assignment.swift +++ b/test/SILGen/assignment.swift @@ -49,3 +49,12 @@ func copyRightToLeft(p: inout P) { // CHECK: end_access [[WRITE]] : $*P p.left = p.right } + +// SR-5919 +func stupidGames() -> ((), ()) { + return ((), ()) +} + +func assignToNestedVoid() { + let _: ((), ()) = stupidGames() +} \ No newline at end of file