Skip to content

Commit a4cb367

Browse files
authored
Mics fix for EmptyView and TupleView (#491)
- Fix TupleView._makeViewList to use makeList.inputs instead of original inputs parameter in concat calls - Update EmptyView._viewListCount to respect .isNonEmptyParent option - Add unit tests for EmptyView._viewListCount
1 parent 0f9c1b9 commit a4cb367

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

Sources/OpenSwiftUICore/View/EmptyView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public struct EmptyView: PrimitiveView {
4242

4343
@available(OpenSwiftUI_v2_0, *)
4444
nonisolated public static func _viewListCount(inputs: _ViewListCountInputs) -> Int? {
45-
0
45+
inputs.options.contains(.isNonEmptyParent) ? 1 : 0
4646
}
4747
}

Sources/OpenSwiftUICore/View/TupleView.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// TupleView.swift
33
// OpenSwiftUICore
44
//
5+
// Audited for 6.5.4
56
// Status: Complete
67
// ID: 79611CB2B7848ECB3D9EC1F26B13F28F (SwiftUI)
78
// ID: DE681AB5F1A334FA14ECABDE70CB1955 (SwiftUICore)
89

910
import OpenAttributeGraphShims
1011

11-
// MARK: - TupleView [6.4.41]
12+
// MARK: - TupleView
1213

1314
/// A View created from a swift tuple of View values.
1415
@available(OpenSwiftUI_v1_0, *)
@@ -45,21 +46,21 @@ public struct TupleView<T>: PrimitiveView, View {
4546
var makeList = MakeList(
4647
view: view,
4748
inputs: inputs,
48-
index: 0,
49-
offset: 0,
50-
wrapChildren: inputs.options.contains(.tupleViewCreatesUnaryElements),
51-
outputs: []
49+
wrapChildren: inputs.options.contains(.tupleViewCreatesUnaryElements)
5250
)
5351
if inputs.options.contains(.tupleViewCreatesUnaryElements),
5452
makeList.inputs.options.contains(.tupleViewCreatesUnaryElements) {
5553
makeList.inputs.options.subtract([.requiresSections, .tupleViewCreatesUnaryElements])
5654
}
55+
guard !contentTypes.isEmpty else {
56+
return _ViewListOutputs.concat([], inputs: makeList.inputs)
57+
}
5758
for (index, conformance) in contentTypes {
5859
makeList.index = index
5960
makeList.offset = tupleType.elementOffset(at: index)
6061
conformance.visitType(visitor: &makeList)
6162
}
62-
return _ViewListOutputs.concat(makeList.outputs, inputs: inputs)
63+
return _ViewListOutputs.concat(makeList.outputs, inputs: makeList.inputs)
6364
}
6465

6566
@available(OpenSwiftUI_v2_0, *)
@@ -70,7 +71,7 @@ public struct TupleView<T>: PrimitiveView, View {
7071
if inputs.options.contains(.tupleViewCreatesUnaryElements) {
7172
return contentTypes.count
7273
} else {
73-
var countViews = CountViews(inputs: inputs, result: 0)
74+
var countViews = CountViews(inputs: inputs)
7475
for contentType in contentTypes {
7576
contentType.1.visitType(visitor: &countViews)
7677
}
@@ -94,10 +95,10 @@ public struct TupleView<T>: PrimitiveView, View {
9495
private struct MakeList: ViewTypeVisitor {
9596
var view: _GraphValue<TupleView<T>>
9697
var inputs: _ViewListInputs
97-
var index: Int
98-
var offset: Int
98+
var index: Int = .zero
99+
var offset: Int = .zero
99100
let wrapChildren: Bool
100-
var outputs: [_ViewListOutputs]
101+
var outputs: [_ViewListOutputs] = []
101102

102103
mutating func visit<V>(type: V.Type) where V : View {
103104
inputs.base.pushStableIndex(index)
@@ -114,7 +115,7 @@ public struct TupleView<T>: PrimitiveView, View {
114115

115116
private struct CountViews: ViewTypeVisitor {
116117
var inputs: _ViewListCountInputs
117-
var result: Int?
118+
var result: Int? = .zero
118119

119120
mutating func visit<V>(type: V.Type) where V : View {
120121
guard let oldResult = result,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// EmptyViewTests.swift
3+
// OpenSwiftUICoreTests
4+
5+
@_spi(ForOpenSwiftUIOnly)
6+
import OpenSwiftUICore
7+
import Testing
8+
9+
struct EmptyViewTests {
10+
@Test("Test EmptyView._viewListCount with various options")
11+
func viewListCount() {
12+
let base = _ViewListCountInputs(.init(.invalid))
13+
var inputs = base
14+
inputs.options = []
15+
#expect(EmptyView._viewListCount(inputs: inputs) == 0)
16+
17+
inputs.options = [.isNonEmptyParent]
18+
#expect(EmptyView._viewListCount(inputs: inputs) == 1)
19+
}
20+
}

0 commit comments

Comments
 (0)