ast, parser: patches for VLS ()

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 name string
typ Type typ Type
expected_type Type expected_type Type
parent_type Type
} }
pub struct StructInitEmbed { pub struct StructInitEmbed {
@ -1122,7 +1123,7 @@ pub:
pub struct AsmAddressing { pub struct AsmAddressing {
pub: pub:
scale int = -1 // 1, 2, 4, or 8 literal scale int = -1 // 1, 2, 4, or 8 literal
mode AddressingMode mode AddressingMode
pos token.Position pos token.Position
pub mut: pub mut:
@ -1463,12 +1464,14 @@ pub fn (expr Expr) is_blank_ident() bool {
pub fn (expr Expr) position() token.Position { pub fn (expr Expr) position() token.Position {
// all uncommented have to be implemented // 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 { match expr {
AnonFn { AnonFn {
return expr.decl.pos return expr.decl.pos
} }
EmptyExpr { EmptyExpr {
println('compiler bug, unhandled EmptyExpr position()') // println('compiler bug, unhandled EmptyExpr position()')
return token.Position{} return token.Position{}
} }
NodeError, ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr, NodeError, ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr, CastExpr,
@ -1755,7 +1758,7 @@ pub fn (node Node) children() []Node {
} }
} else { } else {
match node { match node {
GlobalField, ConstField, EnumField, StructInitField { GlobalField, ConstField, EnumField, StructInitField, CallArg {
children << node.expr children << node.expr
} }
SelectBranch { 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 10 | foo = Color.red
11 | println(color == 0) 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 9 | color = 1
10 | foo = Color.red 10 | foo = Color.red
11 | println(color == 0) 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) 10 | println(Color.red && Color.green)
11 | 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) 8 | println(Color.red > Color.green)
9 | println(Color.red + Color.green) 9 | println(Color.red + Color.green)
10 | println(Color.red && Color.green) 10 | println(Color.red && Color.green)
| ~~ | ~~~~~~~~~
11 | println(Color.red | Color.green) 11 | println(Color.red | Color.green)
12 | 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 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) 11 | println(FilePerm.write && FilePerm.exec)
12 | } 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) 9 | println(FilePerm.read > FilePerm.write)
10 | println(FilePerm.write + FilePerm.exec) 10 | println(FilePerm.write + FilePerm.exec)
11 | println(FilePerm.write && FilePerm.exec) 11 | println(FilePerm.write && FilePerm.exec)
| ~~ | ~~~~~~~~~~~~~~
12 | } 12 | }

View File

@ -2024,6 +2024,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
} }
// `Color.green` // `Color.green`
mut enum_name := p.check_name() mut enum_name := p.check_name()
enum_name_pos := p.prev_tok.position()
if mod != '' { if mod != '' {
enum_name = mod + '.' + enum_name enum_name = mod + '.' + enum_name
} else { } else {
@ -2037,7 +2038,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
return ast.EnumVal{ return ast.EnumVal{
enum_name: enum_name enum_name: enum_name
val: val val: val
pos: p.tok.position() pos: enum_name_pos.extend(p.prev_tok.position())
mod: mod mod: mod
} }
} else if language == .js && p.peek_tok.kind == .dot && p.peek_token(2).kind == .name { } 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 left: left
name: field_name name: field_name
args: args args: args
name_pos: name_pos
pos: pos pos: pos
is_method: true is_method: true
generic_types: generic_types 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 name_pos: first_field_pos
comments: comments comments: comments
next_comments: nline_comments next_comments: nline_comments
parent_type: typ
} }
} }
} }