cgen: fix sizeof('str') and sizeof(r'str') (#14507)
parent
953ef1f8c9
commit
5ade39f8db
|
@ -5450,11 +5450,13 @@ fn (mut g Gen) size_of(node ast.SizeOf) {
|
|||
g.error('unknown type `$sym.name`', node.pos)
|
||||
}
|
||||
if node.expr is ast.StringLiteral {
|
||||
g.write('sizeof("$node.expr.val")')
|
||||
} else {
|
||||
styp := g.typ(node_typ)
|
||||
g.write('sizeof(${util.no_dots(styp)})')
|
||||
if node.expr.language == .c {
|
||||
g.write('sizeof("$node.expr.val")')
|
||||
return
|
||||
}
|
||||
}
|
||||
styp := g.typ(node_typ)
|
||||
g.write('sizeof(${util.no_dots(styp)})')
|
||||
}
|
||||
|
||||
fn (mut g Gen) enum_val(node ast.EnumVal) {
|
||||
|
|
|
@ -25,5 +25,6 @@ fn test_sizeof() {
|
|||
assert sizeof(flag.Flag) > 4
|
||||
|
||||
assert sizeof(c'hello') == 6
|
||||
assert sizeof(r'hello') == 6
|
||||
assert sizeof(r'hello') == 16
|
||||
assert sizeof('hello') == 16
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue