checker: correct underline for unknown type in method type (#7223)
parent
e6d162ad65
commit
0bf679a7aa
|
@ -269,6 +269,7 @@ pub:
|
||||||
receiver Field
|
receiver Field
|
||||||
receiver_pos token.Position
|
receiver_pos token.Position
|
||||||
is_method bool
|
is_method bool
|
||||||
|
method_type_pos token.Position
|
||||||
method_idx int
|
method_idx int
|
||||||
rec_mut bool // is receiver mutable
|
rec_mut bool // is receiver mutable
|
||||||
rec_share table.ShareType
|
rec_share table.ShareType
|
||||||
|
|
|
@ -4573,7 +4573,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||||
for arg in node.params {
|
for arg in node.params {
|
||||||
sym := c.table.get_type_symbol(arg.typ)
|
sym := c.table.get_type_symbol(arg.typ)
|
||||||
if sym.kind == .placeholder {
|
if sym.kind == .placeholder {
|
||||||
c.error('unknown type `$sym.name`', node.pos)
|
c.error('unknown type `$sym.name`', node.method_type_pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
mut rec_name := ''
|
mut rec_name := ''
|
||||||
mut is_method := false
|
mut is_method := false
|
||||||
mut receiver_pos := token.Position{}
|
mut receiver_pos := token.Position{}
|
||||||
|
mut rec_type_pos := token.Position{}
|
||||||
mut rec_type := table.void_type
|
mut rec_type := table.void_type
|
||||||
mut rec_mut := false
|
mut rec_mut := false
|
||||||
mut params := []table.Param{}
|
mut params := []table.Param{}
|
||||||
|
@ -194,7 +195,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
// }
|
// }
|
||||||
// TODO: talk to alex, should mut be parsed with the type like this?
|
// 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
|
// or should it be a property of the arg, like this ptr/mut becomes indistinguishable
|
||||||
|
rec_type_pos = p.tok.position()
|
||||||
rec_type = p.parse_type_with_mut(rec_mut)
|
rec_type = p.parse_type_with_mut(rec_mut)
|
||||||
|
rec_type_pos = rec_type_pos.extend(p.prev_tok.position())
|
||||||
if is_amp && rec_mut {
|
if is_amp && rec_mut {
|
||||||
p.error('use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`')
|
p.error('use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`')
|
||||||
return ast.FnDecl{}
|
return ast.FnDecl{}
|
||||||
|
@ -273,7 +276,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
// arrays/maps dont belong to a module only their element types do
|
// arrays/maps dont belong to a module only their element types do
|
||||||
// we could also check if kind is .array, .array_fixed, .map instead of mod.len
|
// we could also check if kind is .array, .array_fixed, .map instead of mod.len
|
||||||
if type_sym.mod.len > 0 && type_sym.mod != p.mod && type_sym.language == .v {
|
if type_sym.mod.len > 0 && type_sym.mod != p.mod && type_sym.language == .v {
|
||||||
p.error('cannot define new methods on non-local type $type_sym.name')
|
p.error_with_pos('cannot define new methods on non-local type $type_sym.name',
|
||||||
|
rec_type_pos)
|
||||||
return ast.FnDecl{}
|
return ast.FnDecl{}
|
||||||
}
|
}
|
||||||
// p.warn('reg method $type_sym.name . $name ()')
|
// p.warn('reg method $type_sym.name . $name ()')
|
||||||
|
@ -346,6 +350,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
}
|
}
|
||||||
receiver_pos: receiver_pos
|
receiver_pos: receiver_pos
|
||||||
is_method: is_method
|
is_method: is_method
|
||||||
|
method_type_pos: rec_type_pos
|
||||||
method_idx: type_sym_method_idx
|
method_idx: type_sym_method_idx
|
||||||
rec_mut: rec_mut
|
rec_mut: rec_mut
|
||||||
language: language
|
language: language
|
||||||
|
|
Loading…
Reference in New Issue