ast, parser: patches for VLS (#9562)

pull/9570/head
Ned Palacios 2021-04-02 22:26:37 +08:00 committed by GitHub
parent af14c808a3
commit 1bb48c3577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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