mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: cleanup in if_expr() (#15347)
This commit is contained in:
parent
9e50803071
commit
ab244d2236
|
@ -59,21 +59,22 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||||
mut comptime_field_name := ''
|
mut comptime_field_name := ''
|
||||||
if mut branch.cond is ast.InfixExpr {
|
if mut branch.cond is ast.InfixExpr {
|
||||||
if branch.cond.op == .key_is {
|
if branch.cond.op == .key_is {
|
||||||
if branch.cond.right !is ast.TypeNode && branch.cond.right !is ast.ComptimeType {
|
left := branch.cond.left
|
||||||
|
right := branch.cond.right
|
||||||
|
if right !in [ast.TypeNode, ast.ComptimeType] {
|
||||||
c.error('invalid `\$if` condition: expected a type', branch.cond.right.pos())
|
c.error('invalid `\$if` condition: expected a type', branch.cond.right.pos())
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
left := branch.cond.left
|
if right is ast.ComptimeType && left is ast.TypeNode {
|
||||||
if branch.cond.right is ast.ComptimeType && left is ast.TypeNode {
|
|
||||||
is_comptime_type_is_expr = true
|
is_comptime_type_is_expr = true
|
||||||
checked_type := c.unwrap_generic(left.typ)
|
checked_type := c.unwrap_generic(left.typ)
|
||||||
skip_state = if c.table.is_comptime_type(checked_type, branch.cond.right as ast.ComptimeType) {
|
skip_state = if c.table.is_comptime_type(checked_type, right as ast.ComptimeType) {
|
||||||
.eval
|
.eval
|
||||||
} else {
|
} else {
|
||||||
.skip
|
.skip
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
got_type := c.unwrap_generic((branch.cond.right as ast.TypeNode).typ)
|
got_type := c.unwrap_generic((right as ast.TypeNode).typ)
|
||||||
sym := c.table.sym(got_type)
|
sym := c.table.sym(got_type)
|
||||||
if sym.kind == .placeholder || got_type.has_flag(.generic) {
|
if sym.kind == .placeholder || got_type.has_flag(.generic) {
|
||||||
c.error('unknown type `$sym.name`', branch.cond.right.pos())
|
c.error('unknown type `$sym.name`', branch.cond.right.pos())
|
||||||
|
@ -83,7 +84,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||||
comptime_field_name = left.expr.str()
|
comptime_field_name = left.expr.str()
|
||||||
c.comptime_fields_type[comptime_field_name] = got_type
|
c.comptime_fields_type[comptime_field_name] = got_type
|
||||||
is_comptime_type_is_expr = true
|
is_comptime_type_is_expr = true
|
||||||
} else if branch.cond.right is ast.TypeNode && left is ast.TypeNode
|
} else if right is ast.TypeNode && left is ast.TypeNode
|
||||||
&& sym.kind == .interface_ {
|
&& sym.kind == .interface_ {
|
||||||
is_comptime_type_is_expr = true
|
is_comptime_type_is_expr = true
|
||||||
// is interface
|
// is interface
|
||||||
|
|
Loading…
Reference in New Issue
Block a user