mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This looks like it was never properly implemented, since when we generate the memberwise initializer for the struct in SILGen, it incorrectly tries to apply the entire initializer expression to each variable binding in the pattern, rather than destructuring the result and pattern-matching it to the variables. Since it never worked it doesn't look like anyone is using this, so let's put up an error saying it's unsupported until we can implement it properly. Add `StructLetDestructuring` as an experimental feature flag so that tests around the feature for things like module interface printing can still work.
91 lines
3.8 KiB
Swift
91 lines
3.8 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
// 1. Build ../stored-properties.swift to a dylib and emit its interface in %t
|
|
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(StoredProperties)) -enable-experimental-feature StructLetDestructuring -emit-module-interface-path %t/StoredProperties.swiftinterface %S/stored-properties.swift -module-name StoredProperties -swift-version 5
|
|
// RUN: %target-swift-typecheck-module-from-interface(%t/StoredProperties.swiftinterface) -module-name StoredProperties
|
|
|
|
// 2. Build this file and link with StoredProperties
|
|
|
|
// RUN: %target-build-swift -enable-experimental-feature StructLetDestructuring %s -I %t -L %t -lStoredProperties -o %t/stored-properties-client %target-rpath(%t)
|
|
|
|
// 3. Codesign and run this, and ensure it exits successfully.
|
|
|
|
// RUN: %target-codesign %t/stored-properties-client %t/%target-library-name(StoredProperties)
|
|
// RUN: %target-run %t/stored-properties-client %t/%target-library-name(StoredProperties)
|
|
|
|
// 4. Repeat these steps, with library evolution enabled.
|
|
|
|
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(StoredProperties)) -enable-experimental-feature StructLetDestructuring -emit-module-interface-path %t/StoredProperties.swiftinterface %S/stored-properties.swift -module-name StoredProperties -swift-version 5 -enable-library-evolution
|
|
|
|
// RUN: %target-build-swift -enable-experimental-feature StructLetDestructuring %s -I %t -L %t -lStoredProperties -o %t/stored-properties-client %target-rpath(%t)
|
|
// RUN: %target-codesign %t/stored-properties-client %t/%target-library-name(StoredProperties)
|
|
// RUN: %target-run %t/stored-properties-client %t/%target-library-name(StoredProperties)
|
|
|
|
import StdlibUnittest
|
|
import StoredProperties
|
|
|
|
/// This test makes sure clients of a parseable interface see correct type
|
|
/// layout and use the right access patterns in the presence of a
|
|
/// .swiftinterface file, in both resilient and non-resilient cases.
|
|
|
|
/// Test that we call the correct accessors in a resilient module, and that
|
|
/// we use trivial storage accesses in a non-resilient module.
|
|
|
|
var StoredPropertyTests = TestSuite("StoredProperty")
|
|
|
|
StoredPropertyTests.test("Getting/NonFixedLayout") {
|
|
var value = HasStoredProperties()
|
|
expectEqual(3, value.computedGetter)
|
|
expectEqual(3, value.computedGetSet)
|
|
expectEqual(0, value.simpleStoredImmutable)
|
|
expectEqual(0, value.simpleStoredMutable)
|
|
expectEqual(false, value.storedWithObservers)
|
|
expectEqual(0, value.storedPrivateSet)
|
|
}
|
|
|
|
StoredPropertyTests.test("Setting/NonFixedLayout") {
|
|
var value = HasStoredProperties()
|
|
value.storedWithObservers = true
|
|
value.computedGetSet = 4
|
|
value.simpleStoredMutable = 4
|
|
|
|
expectEqual(3, value.computedGetter)
|
|
expectEqual(3, value.computedGetSet)
|
|
expectEqual(0, value.simpleStoredImmutable)
|
|
expectEqual(4, value.simpleStoredMutable)
|
|
expectEqual(true, value.storedWithObservers)
|
|
expectEqual(0, value.storedPrivateSet)
|
|
}
|
|
|
|
StoredPropertyTests.test("Getting/FixedLayout") {
|
|
var value = HasStoredPropertiesFixedLayout()
|
|
expectEqual(0, value.simpleStoredMutable.a)
|
|
expectEqual(false, value.simpleStoredMutable.b)
|
|
expectEqual(0, value.simpleStoredMutable.c)
|
|
|
|
expectEqual(0, value.storedWithObservers.a)
|
|
expectEqual(false, value.storedWithObservers.b)
|
|
expectEqual(0, value.storedWithObservers.c)
|
|
}
|
|
|
|
StoredPropertyTests.test("Setting/FixedLayout") {
|
|
var value = HasStoredPropertiesFixedLayout()
|
|
|
|
value.simpleStoredMutable = BagOfVariables()
|
|
expectEqual(0, value.simpleStoredMutable.a)
|
|
expectEqual(false, value.simpleStoredMutable.b)
|
|
expectEqual(0, value.simpleStoredMutable.c)
|
|
|
|
value.storedWithObservers = BagOfVariables()
|
|
expectEqual(0, value.storedWithObservers.a)
|
|
expectEqual(false, value.storedWithObservers.b)
|
|
expectEqual(0, value.storedWithObservers.c)
|
|
}
|
|
|
|
runAllTests()
|