v
v copied to clipboard
CLang build error
OS: macos 12.4 V version: 0.3.0 d8b0df1 Processor: 8 core intel What did you do?
v := r.read_reply() or {
if err is RedisError {
if err == proto.nil_value {
Empty(0)
} else {
err
}
} else {
panic(err)
}
}
function header
pub fn (mut r Reader) read_reply() ?Any
any type declaration
type Any = Empty | RedisError | []Any | big.Integer | bool | f64 | i64 | map[voidptr]Any | string
What did you expect to see?
successfull build, err should smart casted to RedisError struct
What did you see instead?
clang error, its not smartcasted err variable to RedisError, he declared err as IError
/tmp/v/test_session_216517193/reader_test.9028331186495633938.tmp.c:25644:122: error: incompatible operand types ('internal__proto__Any' (aka 'struct internal__proto__Any') and 'IError' (aka 'struct IError'))
_t6 = (internal__proto__RedisError_struct_eq(*(err._internal__proto__RedisError), _const_internal__proto__nil_value) ? (internal__proto__Empty_to_sumtype_internal__proto__Any(ADDR(internal__proto__Empty, (((internal__proto__Empty)(0)))))) : (err));
its working when i recreate err, as RedisError struct
Complete examples are always better. Otherwise, you have to hope someone who has already seen code like yours might have a way to try to duplicate the problem.
reproduce it in playground https://devbits.app/play/RSDZ6WYjbTWC
Works:
module main
struct TestError {
Error
}
type Any = TestError | int
fn get_error() ?Any {
return IError(TestError{})
}
fn main() {
e := get_error() or {
if err is TestError {
println('this is TestError')
TestError(*err) // <- Works!
} else {
panic(err)
}
}
println('result: $e')
}
this is TestError
result: Any(TestError{
Error: Error{}
})
@StunxFS but should it work like this? we already smartcasted it