allowing 0 idk

This commit is contained in:
Jakub Doka 2024-11-03 22:54:05 +01:00
parent 999b25df8b
commit e8f1d2af8c
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 13 additions and 16 deletions

View file

@ -2394,18 +2394,10 @@ impl<'a> Codegen<'a> {
Expr::Idk { pos } => { Expr::Idk { pos } => {
inference!(ty, ctx, self, pos, "value", "@as(<ty>, idk)"); inference!(ty, ctx, self, pos, "value", "@as(<ty>, idk)");
if matches!(ty.expand(), ty::Kind::Struct(_) | ty::Kind::Slice(_)) { if ty.loc(self.tys) == Loc::Stack {
Some(Value::ptr(self.new_stack(ty)).ty(ty)) Some(Value::ptr(self.new_stack(ty)).ty(ty))
} else { } else {
self.report( Some(self.ci.nodes.new_const_lit(ty, 0))
pos,
fa!(
"type '{}' cannot be uninitialized, use a zero \
value instead ('null' in case of pointers)",
self.ty_display(ty)
),
);
Value::NEVER
} }
} }
Expr::Bool { value, .. } => Some(self.ci.nodes.new_const_lit(ty::Id::BOOL, value)), Expr::Bool { value, .. } => Some(self.ci.nodes.new_const_lit(ty::Id::BOOL, value)),
@ -4052,8 +4044,10 @@ impl<'a> Codegen<'a> {
fn finalize(&mut self, prev_err_len: usize) -> bool { fn finalize(&mut self, prev_err_len: usize) -> bool {
self.ci.finalize(&mut self.pool.nid_stack, self.tys, self.files); self.ci.finalize(&mut self.pool.nid_stack, self.tys, self.files);
for (_, node) in self.ci.nodes.iter() { for (_, node) in self.ci.nodes.iter() {
if let Kind::Assert { kind: AssertKind::NullCheck, pos } = node.kind { let Kind::Assert { kind, pos } = node.kind else { continue };
match node.ty {
match kind {
AssertKind::NullCheck => match node.ty {
ty::Id::NEVER => { ty::Id::NEVER => {
self.report( self.report(
pos, pos,
@ -4069,7 +4063,7 @@ impl<'a> Codegen<'a> {
('if <opt> == null { /* handle */ } else { /* use opt */ }')", ('if <opt> == null { /* handle */ } else { /* use opt */ }')",
); );
} }
} },
} }
} }
self.errors.borrow().len() == prev_err_len self.errors.borrow().len() == prev_err_len

View file

@ -1,3 +1,6 @@
test.hb:3:16: type 'int' cannot be uninitialized, use a zero value instead ('null' in case of pointers) main:
a := @as(int, idk) LI64 r1, 0d
^ JALA r0, r31, 0a
code size: 29
ret: 0
status: Ok(())