Open bcardiff opened 1 year ago
I add more information: Running crystal i bug.cr
with the above code works fine, as well as first loading a file requiring zlib, and then dropping to the interpreter for executing the rest of the lines.
So looks like this is related to #12624
Not really, or at least it's hard to see the connection: it doesn't fail because of a missing lib symbol.
I suspect both are related to the underlying problem that REPL mode does not recalculate types.
As a workaround I ended up needing to duplicate the ivar initializers, between the prelude and the requires of the actual files.
# require or eval this whole patch
class Compress::Zlib::Reader < IO
@in_buffer = Pointer(UInt8).null
@out_buffer = Pointer(UInt8).null
@in_buffer_rem = Bytes.empty
@out_count = 0
@sync = false
@read_buffering = true
@flush_on_newline = false
@buffer_size = IO::DEFAULT_BUFFER_SIZE
end
class Compress::Deflate::Reader < IO
@in_buffer = Pointer(UInt8).null
@out_buffer = Pointer(UInt8).null
@in_buffer_rem = Bytes.empty
@out_count = 0
@sync = false
@read_buffering = true
@flush_on_newline = false
@buffer_size = IO::DEFAULT_BUFFER_SIZE
end
require "compress/zlib"
require "compress/deflate"
Then the following snippet can be evaluated in the interpreter successfully
require "compress/zlib"
require "io/multi_writer"
io = IO::Memory.new
mio = IO::MultiWriter.new(io)
mio << "a"
I have reproduced this either in Crystal 1.9.2 and on master 5ed476a41adf0719fc540e6c072a521b4c8ed3ec
The following code compiles fine
But when executed in the interpreter (REPL) it fails with a typing issue.
If we remove the
require "compress/zlib"
the code is interpreted just fine.