mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: add Expr to AsCast
This commit is contained in:
parent
06df6d25a2
commit
81ce524705
@ -411,6 +411,7 @@ pub:
|
||||
|
||||
pub struct AsCast {
|
||||
pub:
|
||||
expr Expr
|
||||
typ table.Type
|
||||
}
|
||||
|
||||
|
@ -308,6 +308,11 @@ fn (f mut Fmt) expr(node ast.Expr) {
|
||||
f.write(']')
|
||||
}
|
||||
}
|
||||
ast.AsCast {
|
||||
type_str := f.table.type_to_str(it.typ)
|
||||
f.expr(it.expr)
|
||||
f.write(' as $type_str')
|
||||
}
|
||||
ast.AssignExpr {
|
||||
f.expr(it.left)
|
||||
f.write(' $it.op.str() ')
|
||||
|
@ -123,6 +123,10 @@ pub mut:
|
||||
pub_mut_field string
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
val int
|
||||
}
|
||||
|
||||
const (
|
||||
reserved_types = {
|
||||
'i8': true
|
||||
@ -188,3 +192,13 @@ fn fn_with_match_expr() {
|
||||
fn fn_variadic(arg int, args ...string) {
|
||||
println('Do nothing')
|
||||
}
|
||||
|
||||
fn test_as() {
|
||||
a := sum_expr() as Bar
|
||||
}
|
||||
|
||||
fn sum_expr() FooBar {
|
||||
return Bar{
|
||||
val: 5
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,12 @@ struct Foo {
|
||||
pub_mut_field string
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
val int
|
||||
}
|
||||
|
||||
type FooBar = Foo | Bar
|
||||
|
||||
const (
|
||||
reserved_types = {
|
||||
'i8': true
|
||||
@ -188,3 +194,11 @@ fn fn_with_match_expr() {
|
||||
fn fn_variadic(arg int, args... string) {
|
||||
println('Do nothing')
|
||||
}
|
||||
|
||||
fn test_as() {
|
||||
a := sum_expr() as Bar
|
||||
}
|
||||
|
||||
fn sum_expr() FooBar {
|
||||
return Bar{ val: 5 }
|
||||
}
|
||||
|
@ -766,6 +766,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
|
||||
p.next()
|
||||
typ = p.parse_type()
|
||||
node = ast.AsCast{
|
||||
expr: node
|
||||
typ: typ
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user