Commit 0f937b64

0f937b6405e9Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Implement File.readlines

File.readlines(path) was unwired -- the constant-receiver dispatch had no readlines arm, so it fell through to the generic call and emitted 0 ("cannot resolve call to 'readlines'").

Route it to sp_str_lines(sp_file_read(path)): read the whole file, then split on "\n" keeping the terminator (CRuby's default $/). Splitting on real newlines is more correct than mirroring the stdin sp_readlines() path, which uses a 4096-byte fgets buffer and would break any line longer than 4095 chars.

  • codegen: File.readlines(path[, chomp: true]) takes the first positional arg as the path; a trailing keyword hash (encoding:, chomp:) is not the path. chomp: true routes to sp_str_lines_chomp.
  • analyze: types it str_array alongside read/binread.

File.readlines("f") # => ["a\n", "b\n"] (was 0) File.readlines("f", chomp: true) # => ["a", "b"] File.readlines("f", encoding: 'utf-8') # encoding accepted, ignored

A missing file yields [] rather than raising Errno::ENOENT, inherited from and consistent with File.read (sp_file_read returns "" when fopen fails); the broader ENOENT gap is out of scope here.

Fixes #1125

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
0f937b6405e9
Parent
ef8438164a86

spinel_analyze.rbmodifiedView file

@@ -6691,6 +6691,9 @@
66916691 if mname == "read" || mname == "binread"
66926692 return "string"
66936693 end
6694+ if mname == "readlines"
6695+ return "str_array"
6696+ end
66946697 if mname == "mtime"
66956698 return "time"
66966699 end