You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The net.TcpConn implements io.ReaderWriter, as of https://github.com/vlang/v/blob/master/vlib/io/readerwriter.v#L6 the io.ReaderWriter contain io.Writer so it inherits all methods.
(I need both io.Reader and io.Writer capabilities in full code)
If I try to pass field of type io.ReaderWriter to field of type io.Writer I get an error:
python3 script I use to trigger go handle_conn(mut c):
importsocketHOST='127.0.0.1'# The server's hostname or IP addressPORT=42228# The port used by the servers=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall("test".encode("utf-8"))
data=s.recv(409600)
print(data.decode())
Run v code, run python script (more in Current Behavior)
Expected Behavior
io.ReaderWriter as a superset of io.Writer should be casted to io.Writer as it contains all methods of io.Writer. For now I guess compiler is uncapable of that
Current Behavior
Errors either in runtime or compile time unable to use io.ReaderWriter as io.Writer
to reproduce: run v code, get an error:
TCP JSON-RPC server on 127.0.0.1:42228 (Content-Length framing)
Accepted
V panic: `as_cast`: cannot convert net.TcpConn to io.Writer
v hash: e3616f2
pid: 0000000000000C14
tid: 00000000000031A4
C:/Users/Te4nick/AppData/Local/Temp/v_0/interfaces.01KEH09VF1D4BJPKC3VE1K48MA.tmp.c:7710: at builtin___v_panic: Backtrace
C:/Users/Te4nick/AppData/Local/Temp/v_0/interfaces.01KEH09VF1D4BJPKC3VE1K48MA.tmp.c:3211: by I_io__ReaderWriter_as_I_io__Writer
C:/Users/Te4nick/AppData/Local/Temp/v_0/interfaces.01KEH09VF1D4BJPKC3VE1K48MA.tmp.c:10939: by main__Server_writer
C:/Users/Te4nick/AppData/Local/Temp/v_0/interfaces.01KEH09VF1D4BJPKC3VE1K48MA.tmp.c:10943: by main__handle_conn
C:/Users/Te4nick/AppData/Local/Temp/v_0/interfaces.01KEH09VF1D4BJPKC3VE1K48MA.tmp.c:3356: by main__handle_conn_thread_wrapper
00452f8e : by ???
0044f1be : by ???
00452fc8 : by ???
7ffc7f817374 : by ???
Trying to wrap it into if s.stream is io.Writer { ... } also gives no effect.
Possible Solution
Compiler supports casting superset Interfaces to subsets Interfaces normally (io.ReaderWriter as io.Writer)
Describe the bug
The
net.TcpConnimplementsio.ReaderWriter, as of https://github.com/vlang/v/blob/master/vlib/io/readerwriter.v#L6 theio.ReaderWritercontainio.Writerso it inherits all methods.(I need both io.Reader and io.Writer capabilities in full code)
If I try to pass field of type
io.ReaderWriterto field of typeio.WriterI get an error:Reproduction Steps
v code:
python3 script I use to trigger
go handle_conn(mut c):Run v code, run python script (more in Current Behavior)
Expected Behavior
io.ReaderWriteras a superset ofio.Writershould be casted toio.Writeras it contains all methods ofio.Writer. For now I guess compiler is uncapable of thatCurrent Behavior
Errors either in runtime or compile time unable to use
io.ReaderWriterasio.Writerto reproduce: run v code, get an error:
If I as cast s.stream to io.Writer and run (
pub fn (s &Server) writer() &ResponseWriterreplacement):I get an error:
Trying to wrap it into
if s.stream is io.Writer { ... }also gives no effect.Possible Solution
Compiler supports casting superset Interfaces to subsets Interfaces normally (
io.ReaderWriterasio.Writer)Additional Information/Context
No response
V version
V 0.5.0 e6e28f1
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.