checker: fn_call fixes (#9994)

pull/9995/head
Ned Palacios 2021-05-04 17:31:32 +08:00 committed by GitHub
parent 1e856c0f94
commit 177f8f585b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -2135,7 +2135,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
concrete_types << concrete_type concrete_types << concrete_type
} }
} }
if c.cur_fn.cur_concrete_types.len == 0 && has_generic { if !isnil(c.cur_fn) && c.cur_fn.cur_concrete_types.len == 0 && has_generic {
c.error('generic fn using generic types cannot be called outside of generic fn', c.error('generic fn using generic types cannot be called outside of generic fn',
call_expr.pos) call_expr.pos)
} }
@ -2183,10 +2183,12 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
// it was set to anon for checker errors, clear for gen // it was set to anon for checker errors, clear for gen
call_expr.name = '' call_expr.name = ''
c.expr(call_expr.left) c.expr(call_expr.left)
if call_expr.left.typ != ast.Type(0) {
anon_fn_sym := c.table.get_type_symbol(call_expr.left.typ) anon_fn_sym := c.table.get_type_symbol(call_expr.left.typ)
func = (anon_fn_sym.info as ast.FnType).func func = (anon_fn_sym.info as ast.FnType).func
found = true found = true
} }
}
// try prefix with current module as it would have never gotten prefixed // try prefix with current module as it would have never gotten prefixed
if !found && !fn_name.contains('.') && call_expr.mod != 'builtin' { if !found && !fn_name.contains('.') && call_expr.mod != 'builtin' {
name_prefixed := '${call_expr.mod}.$fn_name' name_prefixed := '${call_expr.mod}.$fn_name'
@ -2277,7 +2279,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
&& func.mod != c.mod { && func.mod != c.mod {
c.error('function `$func.name` is private', call_expr.pos) c.error('function `$func.name` is private', call_expr.pos)
} }
if c.cur_fn != 0 && !c.cur_fn.is_deprecated && func.is_deprecated { if !isnil(c.cur_fn) && !c.cur_fn.is_deprecated && func.is_deprecated {
c.deprecate_fnmethod('function', func.name, func, call_expr) c.deprecate_fnmethod('function', func.name, func, call_expr)
} }
if func.is_unsafe && !c.inside_unsafe if func.is_unsafe && !c.inside_unsafe