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
|
// IError holds information about an error instance
|
||||||
pub interface IError {
|
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
|
msg() string
|
||||||
code() int
|
code() int
|
||||||
}
|
}
|
||||||
|
|
@ -34,18 +30,10 @@ pub fn (err IError) str() string {
|
||||||
err.msg()
|
err.msg()
|
||||||
}
|
}
|
||||||
else {
|
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()'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Error is the empty default implementation of `IError`.
|
// Error is the empty default implementation of `IError`.
|
||||||
pub struct Error {}
|
pub struct Error {}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ module builtin
|
||||||
|
|
||||||
// IError holds information about an error instance
|
// IError holds information about an error instance
|
||||||
pub interface IError {
|
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
|
msg() string
|
||||||
code() int
|
code() int
|
||||||
}
|
}
|
||||||
|
|
@ -25,18 +21,10 @@ pub fn (err IError) str() string {
|
||||||
err.msg()
|
err.msg()
|
||||||
}
|
}
|
||||||
else {
|
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()'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Error is the empty default implementation of `IError`.
|
// Error is the empty default implementation of `IError`.
|
||||||
pub struct Error {}
|
pub struct Error {}
|
||||||
|
|
|
||||||
|
|
@ -1373,15 +1373,6 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
||||||
// Verify methods
|
// Verify methods
|
||||||
for imethod in imethods {
|
for imethod in imethods {
|
||||||
method := c.table.find_method_with_embeds(typ_sym, imethod.name) or {
|
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 {
|
typ_sym.find_method_with_generic_parent(imethod.name) or {
|
||||||
c.error("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`",
|
c.error("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`",
|
||||||
pos)
|
pos)
|
||||||
|
|
@ -1419,17 +1410,10 @@ 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
|
// voidptr is an escape hatch, it should be allowed to be passed
|
||||||
if utyp != ast.voidptr_type {
|
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`",
|
c.error("`$styp` doesn't implement field `$ifield.name` of interface `$inter_sym.name`",
|
||||||
pos)
|
pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
inter_sym.info.types << utyp
|
inter_sym.info.types << utyp
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
@ -1757,18 +1741,6 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
|
||||||
return ast.void_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{} {
|
if c.smartcast_mut_pos != token.Pos{} {
|
||||||
c.note('smartcasting requires either an immutable value, or an explicit mut keyword before the value',
|
c.note('smartcasting requires either an immutable value, or an explicit mut keyword before the value',
|
||||||
c.smartcast_mut_pos)
|
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 {
|
if g.pref.build_mode != .build_module {
|
||||||
methods_struct.writeln('\t},')
|
methods_struct.writeln('\t},')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue