diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 6c38c4adfc..dc63996999 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -279,6 +279,7 @@ pub mut: name string typ Type expected_type Type + parent_type Type } pub struct StructInitEmbed { @@ -1122,7 +1123,7 @@ pub: pub struct AsmAddressing { pub: - scale int = -1 // 1, 2, 4, or 8 literal + scale int = -1 // 1, 2, 4, or 8 literal mode AddressingMode pos token.Position pub mut: @@ -1463,12 +1464,14 @@ pub fn (expr Expr) is_blank_ident() bool { pub fn (expr Expr) position() token.Position { // all uncommented have to be implemented + // NB: please do not print here. the language server will hang + // as it uses STDIO primarly to communicate ~Ned match expr { AnonFn { return expr.decl.pos } EmptyExpr { - println('compiler bug, unhandled EmptyExpr position()') + // println('compiler bug, unhandled EmptyExpr position()') return token.Position{} } NodeError, ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, @@ -1755,7 +1758,7 @@ pub fn (node Node) children() []Node { } } else { match node { - GlobalField, ConstField, EnumField, StructInitField { + GlobalField, ConstField, EnumField, StructInitField, CallArg { children << node.expr } SelectBranch { diff --git a/vlib/v/checker/tests/enum_as_int_err.out b/vlib/v/checker/tests/enum_as_int_err.out index 27f32b93a1..be6c8fa26a 100644 --- a/vlib/v/checker/tests/enum_as_int_err.out +++ b/vlib/v/checker/tests/enum_as_int_err.out @@ -5,9 +5,16 @@ vlib/v/checker/tests/enum_as_int_err.vv:9:10: error: cannot assign to `color`: e | ^ 10 | foo = Color.red 11 | println(color == 0) -vlib/v/checker/tests/enum_as_int_err.vv:11:2: error: cannot assign to `foo`: expected `int`, not `Color` +vlib/v/checker/tests/enum_as_int_err.vv:10:8: error: cannot assign to `foo`: expected `int`, not `Color` + 8 | mut foo := 1 + 9 | color = 1 + 10 | foo = Color.red + | ~~~~~~~~~ + 11 | println(color == 0) + 12 | } +vlib/v/checker/tests/enum_as_int_err.vv:11:10: error: infix expr: cannot use `int literal` (right expression) as `Color` 9 | color = 1 10 | foo = Color.red 11 | println(color == 0) - | ~~~~~~~ - 12 | } + | ~~~~~~~~~~ + 12 | } \ No newline at end of file diff --git a/vlib/v/checker/tests/enum_op_err.out b/vlib/v/checker/tests/enum_op_err.out index ecf165700f..1392251852 100644 --- a/vlib/v/checker/tests/enum_op_err.out +++ b/vlib/v/checker/tests/enum_op_err.out @@ -12,11 +12,11 @@ vlib/v/checker/tests/enum_op_err.vv:9:20: error: only `==` and `!=` are defined | ^ 10 | println(Color.red && Color.green) 11 | println(Color.red | Color.green) -vlib/v/checker/tests/enum_op_err.vv:10:20: error: left operand for `&&` is not a boolean +vlib/v/checker/tests/enum_op_err.vv:10:10: error: left operand for `&&` is not a boolean 8 | println(Color.red > Color.green) 9 | println(Color.red + Color.green) 10 | println(Color.red && Color.green) - | ~~ + | ~~~~~~~~~ 11 | println(Color.red | Color.green) 12 | println(Color.red & Color.green) vlib/v/checker/tests/enum_op_err.vv:11:20: error: only `==` and `!=` are defined on `enum`, use an explicit cast to `int` if needed diff --git a/vlib/v/checker/tests/enum_op_flag_err.out b/vlib/v/checker/tests/enum_op_flag_err.out index 1fec5dcf80..fb3e228e0a 100644 --- a/vlib/v/checker/tests/enum_op_flag_err.out +++ b/vlib/v/checker/tests/enum_op_flag_err.out @@ -12,9 +12,9 @@ vlib/v/checker/tests/enum_op_flag_err.vv:10:25: error: only `==`, `!=`, `|` and | ^ 11 | println(FilePerm.write && FilePerm.exec) 12 | } -vlib/v/checker/tests/enum_op_flag_err.vv:11:25: error: left operand for `&&` is not a boolean +vlib/v/checker/tests/enum_op_flag_err.vv:11:10: error: left operand for `&&` is not a boolean 9 | println(FilePerm.read > FilePerm.write) 10 | println(FilePerm.write + FilePerm.exec) 11 | println(FilePerm.write && FilePerm.exec) - | ~~ + | ~~~~~~~~~~~~~~ 12 | } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 7c7aff3e76..f0ad826c50 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2024,6 +2024,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { } // `Color.green` mut enum_name := p.check_name() + enum_name_pos := p.prev_tok.position() if mod != '' { enum_name = mod + '.' + enum_name } else { @@ -2037,7 +2038,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { return ast.EnumVal{ enum_name: enum_name val: val - pos: p.tok.position() + pos: enum_name_pos.extend(p.prev_tok.position()) mod: mod } } else if language == .js && p.peek_tok.kind == .dot && p.peek_token(2).kind == .name { @@ -2236,6 +2237,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { left: left name: field_name args: args + name_pos: name_pos pos: pos is_method: true generic_types: generic_types diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 1a236ec8dc..9f45f38edd 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -409,6 +409,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit { name_pos: first_field_pos comments: comments next_comments: nline_comments + parent_type: typ } } }