Hello! So I have this snippet, which generates an error: 
    
    
    import streams
    
    proc readbin(s: Stream, x: var int8) =
        x = readInt8(s)
    
    proc readbin(s: Stream, x: var int16) =
        x = readInt16(s)
    
    proc readbin(s: Stream, x: var int32) =
        x = readInt32(s)
    
    proc readbin(s: Stream, x: var int64) =
        x = readInt64(s)
    
    proc test(s: Stream) =
        var n: int
        readbin(s, n) #Error: for a 'var' type a variable needs to be passed
    

The error goes away when I give n a more specific type (exactly matching one of 
the proc signatures). My guess is that this happens because there's some 
(redundant) implicit casting going on, so the compiler thinks I'm trying to 
pass an expression rather than a variable. The source of the error was pretty 
difficult to diagnose, especially since the offending line was being generated 
by a macro. If I'm right about the cause, perhaps it would save others some 
pain if the compiler gave a more helpful error message for this particular case.

Reply via email to