From 9bb1867be0ebfba0ea4ded524d6b11d9b4a9eca1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 16 Nov 2022 00:53:37 +0200 Subject: [PATCH] os: refactor `err == IError(os.Eof{})` to `err is os.Eof` --- vlib/os/file_test.v | 4 ++-- vlib/os/os.c.v | 2 +- vlib/os/os_test.v | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index 8da14b71af..f8ec8c1ed8 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -144,7 +144,7 @@ fn test_read_eof_last_read_partial_buffer_fill() { assert false } else { // Expected an error when received end-of-file. - assert err == IError(os.Eof{}) + assert err is os.Eof } f.close() } @@ -176,7 +176,7 @@ fn test_read_eof_last_read_full_buffer_fill() { assert false } else { // Expect an error at EOF. - assert err == IError(os.Eof{}) + assert err is os.Eof } f.close() } diff --git a/vlib/os/os.c.v b/vlib/os/os.c.v index 28d16c891b..68e66fb3aa 100644 --- a/vlib/os/os.c.v +++ b/vlib/os/os.c.v @@ -89,7 +89,7 @@ fn slurp_file_in_builder(fp &C.FILE) !strings.Builder { mut sb := strings.new_builder(os.buf_size) for { mut read_bytes := fread(&buf[0], 1, os.buf_size, fp) or { - if err == IError(Eof{}) { + if err is Eof { break } unsafe { sb.free() } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index ea1642f9f6..6a90159161 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -194,7 +194,7 @@ fn test_write_and_read_bytes() { // check that trying to read data from EOF doesn't error and returns 0 mut a := []u8{len: 5} nread := file_read.read_bytes_into(5, mut a) or { - n := if err == IError(os.Eof{}) { + n := if err is os.Eof { int(0) } else { eprintln(err)