checker: correct underline for unknown type in method type (#7223)

pull/7234/head
Daniel Däschle 2020-12-10 10:51:22 +01:00 committed by GitHub
parent e6d162ad65
commit 0bf679a7aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 28 deletions

View File

@ -259,33 +259,34 @@ pub mut:
pub struct FnDecl { pub struct FnDecl {
pub: pub:
name string name string
mod string mod string
params []table.Param params []table.Param
is_deprecated bool is_deprecated bool
is_pub bool is_pub bool
is_variadic bool is_variadic bool
is_anon bool is_anon bool
receiver Field receiver Field
receiver_pos token.Position receiver_pos token.Position
is_method bool is_method bool
method_idx int method_type_pos token.Position
rec_mut bool // is receiver mutable method_idx int
rec_share table.ShareType rec_mut bool // is receiver mutable
language table.Language rec_share table.ShareType
no_body bool // just a definition `fn C.malloc()` language table.Language
is_builtin bool // this function is defined in builtin/strconv no_body bool // just a definition `fn C.malloc()`
pos token.Position is_builtin bool // this function is defined in builtin/strconv
body_pos token.Position pos token.Position
file string body_pos token.Position
is_generic bool file string
is_direct_arr bool // direct array access is_generic bool
attrs []table.Attr is_direct_arr bool // direct array access
attrs []table.Attr
pub mut: pub mut:
stmts []Stmt stmts []Stmt
return_type table.Type return_type table.Type
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
source_file &File = 0 source_file &File = 0
} }
// break, continue // break, continue

View File

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

View File

@ -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