checker, cgen: fix call of generic function returning normal type (#5865)

pull/5868/head
Uwe Krüger 2020-07-17 18:28:45 +02:00 committed by GitHub
parent e804ba5294
commit ea322bdd97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -1116,7 +1116,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
if f.is_deprecated { if f.is_deprecated {
c.warn('function `$f.name` has been deprecated', call_expr.pos) c.warn('function `$f.name` has been deprecated', call_expr.pos)
} }
if f.is_generic { if f.is_generic && f.return_type.has_flag(.generic) {
rts := c.table.get_type_symbol(f.return_type) rts := c.table.get_type_symbol(f.return_type)
if rts.kind == .struct_ { if rts.kind == .struct_ {
rts_info := rts.info as table.Struct rts_info := rts.info as table.Struct

View File

@ -1785,14 +1785,15 @@ fn (mut g Gen) expr(node ast.Expr) {
} }
ast.SizeOf { ast.SizeOf {
if node.is_type { if node.is_type {
node_typ := g.unwrap_generic(node.typ)
mut styp := node.type_name mut styp := node.type_name
if styp.starts_with('C.') { if styp.starts_with('C.') {
styp = styp[2..] styp = styp[2..]
} }
if node.type_name == '' { if node.type_name == '' || node.typ.has_flag(.generic) {
styp = g.typ(node.typ) styp = g.typ(node_typ)
} else { } else {
sym := g.table.get_type_symbol(node.typ) sym := g.table.get_type_symbol(node_typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as table.Struct info := sym.info as table.Struct
if !info.is_typedef { if !info.is_typedef {

View File

@ -0,0 +1,8 @@
fn getsize<P>() u32 {
return sizeof(P)
}
fn test_sizeof_2() {
assert getsize<f64>() == 8
assert 4 == getsize<int>()
}