Skip to content

[Serialization] InitAccessors: Use correct code for `@storageRestrict… #67351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
}

case DAK_StorageRestrictions: {
auto abbrCode = S.DeclTypeAbbrCodes[AccessesDeclAttrLayout::Code];
auto abbrCode = S.DeclTypeAbbrCodes[StorageRestrictionsDeclAttrLayout::Code];
auto attr = cast<StorageRestrictionsAttr>(DA);

SmallVector<IdentifierID, 4> properties;
Expand Down
66 changes: 66 additions & 0 deletions test/Serialization/init_accessors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/src)
// RUN: %empty-directory(%t/sdk)
// RUN: split-file %s %t/src

// REQUIRES: asserts

// RUN: %target-swift-frontend -emit-module %t/src/PublicModule.swift \
// RUN: -module-name PublicModule -swift-version 5 \
// RUN: -emit-module-path %t/sdk/PublicModule.swiftmodule \
// RUN: -enable-experimental-feature InitAccessors

// RUN: %target-swift-frontend -typecheck %t/src/Client.swift \
// RUN: -enable-experimental-feature InitAccessors \
// RUN: -module-name Client -I %t/sdk

//--- PublicModule.swift
public struct Test<T> {
private var _x: T

public var x: T {
@storageRestrictions(initializes: _x)
init {
_x = newValue
}

get { _x }
set { _x = newValue }
}

public init(data: T) {
self.x = data
}
}

public struct TestMulti<T, U> {
private var _a: T
private var _c: U

public var b: Int

public var data: (T, U) {
@storageRestrictions(initializes: _a, _c, accesses: b)
init {
_a = newValue.0
_c = newValue.1
b = 0
}

get { (_a, _c) }
}

public init(data: (T, U), b: Int) {
self.b = b
self.data = data
}
}

//--- Client.swift
import PublicModule

let test1 = Test<[Int]>(data: [1, 2, 3])
_ = test1.x

let test2 = TestMulti(data: ("Question", 42), b: -1)
_ = print("\(test2.data), \(test2.b)")