checker, cgen: fix call of generic function returning normal type (#5865)
parent
e804ba5294
commit
ea322bdd97
|
@ -1116,7 +1116,7 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||
if f.is_deprecated {
|
||||
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)
|
||||
if rts.kind == .struct_ {
|
||||
rts_info := rts.info as table.Struct
|
||||
|
|
|
@ -1785,14 +1785,15 @@ fn (mut g Gen) expr(node ast.Expr) {
|
|||
}
|
||||
ast.SizeOf {
|
||||
if node.is_type {
|
||||
node_typ := g.unwrap_generic(node.typ)
|
||||
mut styp := node.type_name
|
||||
if styp.starts_with('C.') {
|
||||
styp = styp[2..]
|
||||
}
|
||||
if node.type_name == '' {
|
||||
styp = g.typ(node.typ)
|
||||
if node.type_name == '' || node.typ.has_flag(.generic) {
|
||||
styp = g.typ(node_typ)
|
||||
} else {
|
||||
sym := g.table.get_type_symbol(node.typ)
|
||||
sym := g.table.get_type_symbol(node_typ)
|
||||
if sym.kind == .struct_ {
|
||||
info := sym.info as table.Struct
|
||||
if !info.is_typedef {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fn getsize<P>() u32 {
|
||||
return sizeof(P)
|
||||
}
|
||||
|
||||
fn test_sizeof_2() {
|
||||
assert getsize<f64>() == 8
|
||||
assert 4 == getsize<int>()
|
||||
}
|
Loading…
Reference in New Issue