1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: minor fixes

This commit is contained in:
Alexander Medvednikov
2020-03-18 16:47:37 +01:00
parent c514f0b672
commit fe6707b26d
4 changed files with 8 additions and 7 deletions

View File

@@ -883,7 +883,7 @@ pub fn (c mut Checker) match_expr(node mut ast.MatchExpr) table.Type {
}
pub fn (c mut Checker) if_expr(node mut ast.IfExpr) table.Type {
if c.expected_type != 0 {
if c.expected_type != table.void_type {
// sym := c.table.get_type_symbol(c.expected_type)
// println('$c.file.path $node.pos.line_nr IF: checker exp type = ' + sym.name)
node.is_expr = true

View File

@@ -1089,7 +1089,7 @@ fn (g mut Gen) ident(node ast.Ident) {
// TODO `is`
match node.info {
ast.IdentVar {
if it.is_optional {
if it.is_optional && !g.is_assign_expr {
g.write('/*opt*/')
styp := g.typ(it.typ)[7..] // Option_int => int TODO perf?
g.write('(*($styp*)${name}.data)')
@@ -1103,6 +1103,7 @@ fn (g mut Gen) ident(node ast.Ident) {
}
fn (g mut Gen) if_expr(node ast.IfExpr) {
// g.writeln('/* if is_expr=$node.is_expr */')
// If expression? Assign the value to a temp var.
// Previously ?: was used, but it's too unreliable.
type_sym := g.table.get_type_symbol(node.typ)
@@ -1240,7 +1241,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
g.write('))')
}
}
else if sym.kind == .string {
else if sym.kind == .string && !table.type_is_ptr(node.container_type) {
g.write('string_at(')
g.expr(node.left)
g.write(', ')