1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v2: allow pointers to be initialized with 0

This commit is contained in:
Joe Conigliaro 2020-03-02 23:52:41 +11:00
parent 5b08f307c8
commit 8497d637d9

View File

@ -372,6 +372,8 @@ pub fn (t &Table) check(got, expected Type) bool {
exp_type_sym := t.get_type_symbol(expected)
got_idx := type_idx(got)
exp_idx := type_idx(expected)
// got_is_ptr := type_is_ptr(got)
exp_is_ptr := type_is_ptr(expected)
// println('check: $got_type_sym.name, $exp_type_sym.name')
if got_type_sym.kind == .none_ {
// TODO
@ -386,6 +388,10 @@ pub fn (t &Table) check(got, expected Type) bool {
if got_type_sym.is_int() && exp_type_sym.is_int() {
return true
}
// allow pointers to be initialized with 0. TODO: use none instead
if exp_is_ptr && got_idx == int_type_idx {
return true
}
// allow enum value to be used as int
if (got_type_sym.is_int() && exp_type_sym.kind == .enum_) ||
(exp_type_sym.is_int() && got_type_sym.kind == .enum_) {