cgen: allow "var x : nptr array[etc] etc"

This commit is contained in:
Nigel Tao committed 2023-06-13 10:49:37 +10:00
1 parent dfab0d2b3d
commit 8ac22ceab2
7 files changed
+84 -31

No files matched your search

+8 -1
View File
@@ -358,7 +358,14 @@ func (g *gen) writeVars(b *buffer, f *funk, inStructDecl bool) error {
} else if typ.Eq(typeExprARMCRC32U32) {
b.writes(" = 0;\n")
} else {
b.writes(" = {0};\n")
switch typ.Decorator() {
case t.IDNptr:
b.writes(" = NULL;\n")
case t.IDPtr:
return fmt.Errorf("cannot zero-initialize a non-nullable ptr")
default:
b.writes(" = {0};\n")
}
}
if typ.IsIOType() {