|
|
|
@ -236,7 +236,7 @@ fn (mut c Checker) check_valid_snake_case(name, identifier string, pos token.Pos
|
|
|
|
|
if !c.pref.is_vweb && (name[0] == `_` || name.contains('._')) {
|
|
|
|
|
c.error('$identifier `$name` cannot start with `_`', pos)
|
|
|
|
|
}
|
|
|
|
|
if util.contains_capital(name) {
|
|
|
|
|
if !c.pref.experimental && !c.pref.translated && util.contains_capital(name) {
|
|
|
|
|
c.error('$identifier `$name` cannot contain uppercase letters, use snake_case instead',
|
|
|
|
|
pos)
|
|
|
|
|
}
|
|
|
|
@ -251,7 +251,7 @@ fn stripped_name(name string) string {
|
|
|
|
|
|
|
|
|
|
fn (mut c Checker) check_valid_pascal_case(name, identifier string, pos token.Position) {
|
|
|
|
|
sname := stripped_name(name)
|
|
|
|
|
if !sname[0].is_capital() {
|
|
|
|
|
if !sname[0].is_capital() && !c.pref.translated {
|
|
|
|
|
c.error('$identifier `$name` must begin with capital letter', pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -465,7 +465,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
|
|
|
|
|
if field.has_default_expr || field.name in inited_fields {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if field.typ.is_ptr() {
|
|
|
|
|
if field.typ.is_ptr() && !c.pref.translated {
|
|
|
|
|
c.warn('reference field `${type_sym.name}.$field.name` must be initialized',
|
|
|
|
|
struct_init.pos)
|
|
|
|
|
}
|
|
|
|
@ -694,7 +694,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
|
|
|
|
|
ast.Ident {
|
|
|
|
|
if expr.obj is ast.Var {
|
|
|
|
|
mut v := expr.obj as ast.Var
|
|
|
|
|
if !v.is_mut {
|
|
|
|
|
if !v.is_mut && !c.pref.translated {
|
|
|
|
|
c.error('`$expr.name` is immutable, declare it with `mut` to make it mutable',
|
|
|
|
|
expr.pos)
|
|
|
|
|
}
|
|
|
|
@ -737,7 +737,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
|
|
|
|
|
c.error('unknown field `${type_str}.$expr.field_name`', expr.pos)
|
|
|
|
|
return '', pos
|
|
|
|
|
}
|
|
|
|
|
if !field_info.is_mut {
|
|
|
|
|
if !field_info.is_mut && !c.pref.translated {
|
|
|
|
|
type_str := c.table.type_to_str(expr.expr_type)
|
|
|
|
|
c.error('field `$expr.field_name` of struct `$type_str` is immutable',
|
|
|
|
|
expr.pos)
|
|
|
|
@ -1537,7 +1537,8 @@ pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) {
|
|
|
|
|
c.check_valid_pascal_case(decl.name, 'enum name', decl.pos)
|
|
|
|
|
mut seen := []int{}
|
|
|
|
|
for i, field in decl.fields {
|
|
|
|
|
if util.contains_capital(field.name) {
|
|
|
|
|
if !c.pref.experimental && util.contains_capital(field.name) {
|
|
|
|
|
// TODO C2V uses hundreds of enums with capitals, remove -experimental check once it's handled
|
|
|
|
|
c.error('field name `$field.name` cannot contain uppercase letters, use snake_case instead',
|
|
|
|
|
field.pos)
|
|
|
|
|
}
|
|
|
|
@ -2094,7 +2095,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
|
|
|
|
ast.ForStmt {
|
|
|
|
|
c.in_for_count++
|
|
|
|
|
typ := c.expr(node.cond)
|
|
|
|
|
if !node.is_inf && typ.idx() != table.bool_type_idx {
|
|
|
|
|
if !node.is_inf && typ.idx() != table.bool_type_idx && !c.pref.translated {
|
|
|
|
|
c.error('non-bool used as for condition', node.pos)
|
|
|
|
|
}
|
|
|
|
|
// TODO: update loop var type
|
|
|
|
@ -2383,10 +2384,10 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
|
|
|
|
if node.op == .mul && right_type.is_ptr() {
|
|
|
|
|
return right_type.deref()
|
|
|
|
|
}
|
|
|
|
|
if node.op == .bit_not && !right_type.is_int() {
|
|
|
|
|
if node.op == .bit_not && !right_type.is_int() && !c.pref.translated {
|
|
|
|
|
c.error('operator ~ only defined on int types', node.pos)
|
|
|
|
|
}
|
|
|
|
|
if node.op == .not && right_type != table.bool_type_idx {
|
|
|
|
|
if node.op == .not && right_type != table.bool_type_idx && !c.pref.translated {
|
|
|
|
|
c.error('! operator can only be used with bool types', node.pos)
|
|
|
|
|
}
|
|
|
|
|
return right_type
|
|
|
|
@ -2885,7 +2886,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) table.Type {
|
|
|
|
|
if !node.has_else || i < node.branches.len - 1 {
|
|
|
|
|
// check condition type is boolean
|
|
|
|
|
cond_typ := c.expr(branch.cond)
|
|
|
|
|
if cond_typ.idx() !in [table.bool_type_idx, table.void_type_idx] {
|
|
|
|
|
if cond_typ.idx() !in [table.bool_type_idx, table.void_type_idx] && !c.pref.translated {
|
|
|
|
|
// void types are skipped, because they mean the var was initialized incorrectly
|
|
|
|
|
// (via missing function etc)
|
|
|
|
|
typ_sym := c.table.get_type_symbol(cond_typ)
|
|
|
|
@ -3059,7 +3060,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) table.Type {
|
|
|
|
|
is_ok = v.is_mut && v.is_arg && !typ.deref().is_ptr()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !is_ok {
|
|
|
|
|
if !is_ok && !c.pref.translated {
|
|
|
|
|
c.warn('pointer indexing is only allowed in `unsafe` blocks', node.pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|