checker,gen,builtin: remove the IError.str() compatibility hack (fixes toml ci)
parent
e3a3228c4b
commit
5b36eeeeee
|
|
@ -14,10 +14,6 @@ pub fn panic(s string) {
|
|||
|
||||
// IError holds information about an error instance
|
||||
pub interface IError {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
msg string
|
||||
code int // <<
|
||||
msg() string
|
||||
code() int
|
||||
}
|
||||
|
|
@ -34,15 +30,7 @@ pub fn (err IError) str() string {
|
|||
err.msg()
|
||||
}
|
||||
else {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
old_error_style := unsafe { voidptr(&err.msg) != voidptr(&err.code) } // if fields are not defined (new style) they don't have an offset between them
|
||||
if old_error_style {
|
||||
'$err.type_name(): $err.msg'
|
||||
} else {
|
||||
// <<
|
||||
'$err.type_name(): $err.msg()'
|
||||
}
|
||||
'$err.type_name(): $err.msg()'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@ module builtin
|
|||
|
||||
// IError holds information about an error instance
|
||||
pub interface IError {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
msg string
|
||||
code int // <<
|
||||
msg() string
|
||||
code() int
|
||||
}
|
||||
|
|
@ -25,15 +21,7 @@ pub fn (err IError) str() string {
|
|||
err.msg()
|
||||
}
|
||||
else {
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
old_error_style := unsafe { voidptr(&err.msg) != voidptr(&err.code) } // if fields are not defined (new style) they don't have an offset between
|
||||
if old_error_style {
|
||||
'$err.type_name(): $err.msg'
|
||||
} else {
|
||||
// <<
|
||||
'$err.type_name(): $err.msg()'
|
||||
}
|
||||
'$err.type_name(): $err.msg()'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1373,15 +1373,6 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
|||
// Verify methods
|
||||
for imethod in imethods {
|
||||
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') {
|
||||
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
|
||||
}
|
||||
// <<
|
||||
|
||||
typ_sym.find_method_with_generic_parent(imethod.name) or {
|
||||
c.error("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`",
|
||||
pos)
|
||||
|
|
@ -1419,15 +1410,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
|||
}
|
||||
// voidptr is an escape hatch, it should be allowed to be passed
|
||||
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') {
|
||||
// do nothing, necessary warnings are already printed
|
||||
} else {
|
||||
// <<
|
||||
c.error("`$styp` doesn't implement field `$ifield.name` of interface `$inter_sym.name`",
|
||||
pos)
|
||||
}
|
||||
c.error("`$styp` doesn't implement field `$ifield.name` of interface `$inter_sym.name`",
|
||||
pos)
|
||||
}
|
||||
}
|
||||
inter_sym.info.types << utyp
|
||||
|
|
@ -1757,18 +1741,6 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
|
|||
return ast.void_type
|
||||
}
|
||||
|
||||
// >> Hack to allow old style custom error implementations
|
||||
// TODO: remove once deprecation period for `IError` methods has ended
|
||||
if sym.name == 'IError' && (field_name == 'msg' || field_name == 'code') {
|
||||
method := c.table.find_method(sym, field_name) or {
|
||||
c.error('invalid `IError` interface implementation: $err', node.pos)
|
||||
return ast.void_type
|
||||
}
|
||||
c.note('the `.$field_name` field on `IError` is deprecated, use `.${field_name}()` instead.',
|
||||
node.pos)
|
||||
return method.return_type
|
||||
}
|
||||
// <<<
|
||||
if c.smartcast_mut_pos != token.Pos{} {
|
||||
c.note('smartcasting requires either an immutable value, or an explicit mut keyword before the value',
|
||||
c.smartcast_mut_pos)
|
||||
|
|
|
|||
|
|
@ -5484,15 +5484,6 @@ 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' {
|
||||
methods_struct.writeln('\t\t._method_msg = NULL,')
|
||||
methods_struct.writeln('\t\t._method_code = NULL,')
|
||||
}
|
||||
// <<
|
||||
|
||||
if g.pref.build_mode != .build_module {
|
||||
methods_struct.writeln('\t},')
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue