From 825d963ea1a8a87cd949d1015d53fd03804d4e11 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Thu, 27 Mar 2025 11:31:36 +0000 Subject: [PATCH] Use overflow addition in tests to avoid compilation failures (#3155) Motivation: A few tests are failing to compiler on 32-bit platforms with recently nightly toolchains. These tests are skipped if `Int` is 32 bits wide but the compiler doesn't know that. Modifications: - Use overflow addition to stop the compiler from complaining; the addition won't ever actually overflow because of the runtime check done ahead of time. Result: - Tests compile again - Resolves #3154 --- Tests/NIOPosixTests/NonBlockingFileIOTest.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/NIOPosixTests/NonBlockingFileIOTest.swift b/Tests/NIOPosixTests/NonBlockingFileIOTest.swift index 4e452b1f1..6595f50d8 100644 --- a/Tests/NIOPosixTests/NonBlockingFileIOTest.swift +++ b/Tests/NIOPosixTests/NonBlockingFileIOTest.swift @@ -323,7 +323,9 @@ class NonBlockingFileIOTest: XCTestCase { { (filehandle, path) -> Void in let content = try self.fileIO.read( fileHandle: filehandle, - byteCount: Int(Int32.max) + 10, + // There's a runtime check above, use overflow addition to stop the compilation + // from failing on 32-bit platforms. + byteCount: Int(Int32.max) &+ 10, allocator: .init(), eventLoop: self.eventLoop ).wait() @@ -1404,7 +1406,9 @@ extension NonBlockingFileIOTest { { (filehandle, path) -> Void in let content = try await self.fileIO.read( fileHandle: filehandle, - byteCount: Int(Int32.max) + 10, + // There's a runtime check above, use overflow addition to stop the compilation + // from failing on 32-bit platforms. + byteCount: Int(Int32.max) &+ 10, allocator: .init() ) XCTAssertEqual(String(buffer: content), "some-dummy-content")