checker: minor fixes

pull/12793/head
Alexander Medvednikov 2021-12-11 10:56:37 +03:00
parent 19a47abcca
commit a58c539ee6
3 changed files with 32 additions and 32 deletions

View File

@ -1891,13 +1891,6 @@ pub fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_re
}
}
fn is_noreturn_callexpr(expr ast.Expr) bool {
if expr is ast.CallExpr {
return expr.is_noreturn
}
return false
}
pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
prevent_sum_type_unwrapping_once := c.prevent_sum_type_unwrapping_once
c.prevent_sum_type_unwrapping_once = false
@ -2075,7 +2068,6 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
return ast.void_type
}
// TODO: non deferred
pub fn (mut c Checker) const_decl(mut node ast.ConstDecl) {
if node.fields.len == 0 {
c.warn('const block must have at least 1 declaration', node.pos)
@ -2177,30 +2169,6 @@ pub fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
}
}
fn scope_register_it(mut s ast.Scope, pos token.Position, typ ast.Type) {
s.register(ast.Var{
name: 'it'
pos: pos
typ: typ
is_used: true
})
}
fn scope_register_a_b(mut s ast.Scope, pos token.Position, typ ast.Type) {
s.register(ast.Var{
name: 'a'
pos: pos
typ: typ.ref()
is_used: true
})
s.register(ast.Var{
name: 'b'
pos: pos
typ: typ.ref()
is_used: true
})
}
fn (mut c Checker) check_array_init_para_type(para string, expr ast.Expr, pos token.Position) {
sym := c.table.get_type_symbol(c.expr(expr))
if sym.kind !in [.int, .int_literal] {

View File

@ -800,3 +800,27 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
}
return node.return_type
}
fn scope_register_it(mut s ast.Scope, pos token.Position, typ ast.Type) {
s.register(ast.Var{
name: 'it'
pos: pos
typ: typ
is_used: true
})
}
fn scope_register_a_b(mut s ast.Scope, pos token.Position, typ ast.Type) {
s.register(ast.Var{
name: 'a'
pos: pos
typ: typ.ref()
is_used: true
})
s.register(ast.Var{
name: 'b'
pos: pos
typ: typ.ref()
is_used: true
})
}

View File

@ -5,6 +5,7 @@ module checker
import v.ast
import v.pref
// TODO: non deferred
pub fn (mut c Checker) return_stmt(mut node ast.Return) {
c.expected_type = c.table.cur_fn.return_type
mut expected_type := c.unwrap_generic(c.expected_type)
@ -309,3 +310,10 @@ fn uses_return_stmt(stmts []ast.Stmt) bool {
}
return false
}
fn is_noreturn_callexpr(expr ast.Expr) bool {
if expr is ast.CallExpr {
return expr.is_noreturn
}
return false
}