Skip to content

Commit ed1c459

Browse files
authored
Merge pull request #41596 from glessard/se-withMemoryRebound
[test] fix test of `withMemoryRebound`
2 parents 6d97905 + e83ccd3 commit ed1c459

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/stdlib/UnsafePointer.swift.gyb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,20 @@ ${SelfName}TestSuite.test("withMemoryReboundSE0333") {
499499
}
500500

501501
${SelfName}TestSuite.test("withMemoryReboundSE0333.capacity1") {
502-
let mutablePtr = UnsafeMutablePointer<(Int,Bool,UInt8)>.allocate(capacity: 1)
502+
let mutablePtr = UnsafeMutablePointer<(Int,Bool,Int64)>.allocate(capacity: 1)
503+
let i = Int.random(in: 0 ... .max)
504+
mutablePtr.initialize(to: (i, i.isMultiple(of: 2), Int64(0xff & i)))
503505
defer { mutablePtr.deallocate() }
504-
let ptr = ${SelfName}<(Int, Bool, UInt8)>(mutablePtr)
506+
let ptr = ${SelfName}<(Int, Bool, Int64)>(mutablePtr)
505507
// test rebinding to a shorter type with the same alignment
506508
ptr.withMemoryRebound(to: (Int, Bool).self, capacity: 1) {
507509
// Make sure the closure argument is a ${SelfName}
508510
let ptrT: ${SelfName}<(Int, Bool)> = $0
509511
// and that the element is (Int, Bool).
510512
let mutablePtrT = UnsafeMutablePointer(mutating: ptrT)
511513
expectType((Int, Bool).self, &mutablePtrT.pointee)
514+
expectEqual($0.pointee.0, i)
515+
expectEqual($0.pointee.1, i.isMultiple(of: 2))
512516
}
513517
}
514518

0 commit comments

Comments
 (0)