parser: simplify parse_generic_struct_inst_type() (#9801)

pull/9814/head
yuyi 2021-04-19 19:47:39 +08:00 committed by GitHub
parent 22351a6fb7
commit 3158617ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

@ -0,0 +1,28 @@
pub struct Node<T> {
value T
points_to []&Node<T>
}
fn main() {
mid := &Node<string>{
value: 'Middle'
}
finish := &Node<string>{
value: 'Finish'
}
graph := &Node<string>{
value: 'Start'
points_to: [
&Node<string>{
value: 'TopLeft'
points_to: [
finish,
mid,
]
},
]
}
println(graph.points_to[0].value) // 'TopLeft'
}

View File

@ -523,11 +523,6 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type {
}
})
return ast.new_type(idx)
} else {
idx := p.table.find_type_idx(name)
if idx != 0 {
return ast.new_type(idx).set_flag(.generic)
}
}
return p.parse_enum_or_struct_type(name, .v)
return p.parse_enum_or_struct_type(name, .v).set_flag(.generic)
}