Files
swift-mirror/test/Sema/switch-ownership.swift
Joe Groff e46168c626 SILGen: Improve handling of copyable subpatterns in borrowing switches.
A `let` binding of a copyable subpattern can create an independent variable
which should be copyable and consumable without affecting a borrowed
move-only base. In the same way that `borrowing` parameters are
no-implicit-copy, though, explicitly `_borrowing` subpatterns of
copyable type should be no-implicit-copy as well.
2024-02-07 07:21:11 -08:00

59 lines
1.8 KiB
Swift

// RUN: %target-swift-frontend -typecheck -dump-ast %s | %FileCheck %s
struct A {
static func ~=(pattern: B, subject: A) -> Bool { return true }
static func ~=(pattern: C, subject: borrowing A) -> Bool { return true }
static func ~=(pattern: D, subject: consuming A) -> Bool { return true }
}
struct B { }
struct C { }
struct D { }
struct E { }
struct F { }
struct G { }
func ~=(pattern: E, subject: A) -> Bool { return true }
func ~=(pattern: F, subject: borrowing A) -> Bool { return true }
func ~=(pattern: G, subject: consuming A) -> Bool { return true }
// CHECK-LABEL: (func_decl{{.*}} "test(value:)"
func test(value: A) {
// CHECK: (switch_stmt
switch value {
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=borrowing
case B():
break
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=borrowing
case C():
break
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=consuming
case D():
break
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=borrowing
case E():
break
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=borrowing
case F():
break
// CHECK: (case_stmt
// CHECK: (case_label_item ownership=borrowing
// CHECK: (pattern_expr type="A" ownership=consuming
case G():
break
// CHECK: (case_stmt
// CHECK: (case_label_item default ownership=borrowing
default:
break
}
}