checker,gen,builtin: remove the IError.str() compatibility hack (fixes toml ci)

pull/14013/head
Delyan Angelov 2022-04-11 19:43:38 +03:00
parent e3a3228c4b
commit 5b36eeeeee
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 4 additions and 65 deletions

View File

@ -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,17 +30,9 @@ 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()'
}
}
}
}
// Error is the empty default implementation of `IError`.

View File

@ -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,17 +21,9 @@ 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()'
}
}
}
}
// Error is the empty default implementation of `IError`.

View File

@ -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,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
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)
}
}
}
inter_sym.info.types << utyp
}
return true
@ -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)

View File

@ -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},')
}