markused: fix V compiler panics with -skip-unused, for code using generics

pull/12995/head
Delyan Angelov 2021-12-29 09:48:07 +02:00
parent 5607cfbd32
commit 9b8cf1ad37
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 17 additions and 3 deletions

View File

@ -141,6 +141,9 @@ pub fn (mut w Walker) stmt(node ast.Stmt) {
w.table.used_maps++
}
if node.kind == .struct_ {
if node.cond_type == 0 {
return
}
// the .next() method of the struct will be used for iteration:
cond_type_sym := w.table.sym(node.cond_type)
if next_fn := cond_type_sym.find_method('next') {
@ -275,6 +278,9 @@ fn (mut w Walker) expr(node ast.Expr) {
w.expr(node.left)
w.expr(node.index)
w.or_block(node.or_expr)
if node.left_type == 0 {
return
}
sym := w.table.final_sym(node.left_type)
if sym.kind == .map {
w.table.used_maps++
@ -293,6 +299,9 @@ fn (mut w Walker) expr(node ast.Expr) {
w.fn_decl(mut &ast.FnDecl(opmethod.source_fn))
}
}
if node.right_type == 0 {
return
}
right_sym := w.table.sym(node.right_type)
if node.op in [.not_in, .key_in] && right_sym.kind == .map {
w.table.used_maps++
@ -375,6 +384,9 @@ fn (mut w Walker) expr(node ast.Expr) {
w.expr(node.where_expr)
}
ast.StructInit {
if node.typ == 0 {
return
}
sym := w.table.sym(node.typ)
if sym.kind == .struct_ {
info := sym.info as ast.Struct
@ -382,9 +394,11 @@ fn (mut w Walker) expr(node ast.Expr) {
if ifield.has_default_expr {
w.expr(ifield.default_expr)
}
fsym := w.table.sym(ifield.typ)
if fsym.kind == .map {
w.table.used_maps++
if ifield.typ != 0 {
fsym := w.table.sym(ifield.typ)
if fsym.kind == .map {
w.table.used_maps++
}
}
}
}