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

checker: make the method warning an error

This commit is contained in:
Alexander Medvednikov 2020-05-28 15:30:54 +02:00
parent 01dbb25a37
commit 9609b3a9c8
2 changed files with 12 additions and 7 deletions

View File

@ -2441,7 +2441,18 @@ fn (mut c Checker) fn_decl(it ast.FnDecl) {
// }
// Do not allow to modify types from other modules
if sym.mod != c.mod && !c.is_builtin_mod && sym.mod != '' { // TODO remove != ''
c.warn('cannot define methods on types from other modules (' + 'current module is `$c.mod`, `$sym.name` is from `$sym.mod`)',
// remove the method to hide other related errors (`method is private` etc)
mut idx := 0
for i, m in sym.methods {
if m.name == it.name {
println('got it')
idx = i
break
}
}
sym.methods.delete(idx)
//
c.error('cannot define new methods on non-local `$sym.name` (' + 'current module is `$c.mod`, `$sym.name` is from `$sym.mod`)',
it.pos)
}
}

View File

@ -159,12 +159,6 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
// TODO: talk to alex, should mut be parsed with the type like this?
// or should it be a property of the arg, like this ptr/mut becomes indistinguishable
rec_type = p.parse_type_with_mut(rec_mut)
/*
sym := p.table.get_type_symbol(rec_type)
if sym.mod != p.mod { // && sym.mod != '' {
p.warn('cannot define methods on types from other modules (current module is `$p.mod`, `$sym.name` is from `$sym.mod`)')
}
*/
if is_amp && rec_mut {
p.error('use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`')
}