checker,cgen: use faster `sym.idx == ast.error_type_idx` integer comparisons, instead of `sym.name == "IError"`
parent
62032c43db
commit
4c7cdd2a2d
|
@ -87,8 +87,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
|||
}
|
||||
if expected.has_flag(.optional) {
|
||||
sym := c.table.sym(got)
|
||||
if (sym.kind == .interface_ && sym.name == 'IError')
|
||||
|| got in [ast.none_type, ast.error_type] {
|
||||
if sym.idx == ast.error_type_idx || got in [ast.none_type, ast.error_type] {
|
||||
// IErorr
|
||||
return true
|
||||
} else if !c.check_basic(got, expected.clear_flag(.optional)) {
|
||||
return false
|
||||
|
|
|
@ -1375,7 +1375,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
|||
method := c.table.find_method_with_embeds(typ_sym, imethod.name) or {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
if inter_sym.name == 'IError' && (imethod.name == 'msg' || imethod.name == 'code') {
|
||||
if inter_sym.idx == ast.error_type_idx
|
||||
&& (imethod.name == 'msg' || imethod.name == 'code') {
|
||||
c.note("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`. The usage of fields is being deprecated in favor of methods.",
|
||||
pos)
|
||||
continue
|
||||
|
@ -1421,7 +1422,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
|||
if utyp != ast.voidptr_type {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
if inter_sym.name == 'IError' && (ifield.name == 'msg' || ifield.name == 'code') {
|
||||
if inter_sym.idx == ast.error_type_idx
|
||||
&& (ifield.name == 'msg' || ifield.name == 'code') {
|
||||
// do nothing, necessary warnings are already printed
|
||||
} else {
|
||||
// <<
|
||||
|
|
|
@ -2046,7 +2046,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
|
|||
g.write('.msg))')
|
||||
return
|
||||
}
|
||||
if got_sym.kind == .none_ && exp_sym.name == 'IError' {
|
||||
if got_sym.kind == .none_ && exp_sym.idx == ast.error_type_idx {
|
||||
g.expr(expr)
|
||||
return
|
||||
}
|
||||
|
@ -5488,7 +5488,7 @@ static inline __shared__$interface_name ${shared_fn_name}(__shared__$cctype* x)
|
|||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
// fix MSVC not handling empty struct inits
|
||||
if methods.len == 0 && interface_name == 'IError' {
|
||||
if methods.len == 0 && isym.idx == ast.error_type_idx {
|
||||
methods_struct.writeln('\t\t._method_msg = NULL,')
|
||||
methods_struct.writeln('\t\t._method_code = NULL,')
|
||||
}
|
||||
|
|
|
@ -153,7 +153,8 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
|
|||
typ := branch.exprs[sumtype_index] as ast.TypeNode
|
||||
branch_sym := g.table.sym(g.unwrap_generic(typ.typ))
|
||||
g.write('${dot_or_ptr}_typ == _${sym.cname}_${branch_sym.cname}_index')
|
||||
} else if branch.exprs[sumtype_index] is ast.None && sym.name == 'IError' {
|
||||
} else if branch.exprs[sumtype_index] is ast.None
|
||||
&& sym.idx == ast.error_type_idx {
|
||||
g.write('${dot_or_ptr}_typ == _IError_None___index')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue