diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index 42d3e1c1..3d95aecc 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1629,18 +1629,13 @@ impl Codegen { self.ci.free_loc(tal.loc); self.pop_local_snap(checkpoint); match ty::Kind::from_ty(self.ty(target)) { - ty::Kind::Module(idx) => Some(Value::ty( - self.find_or_declare(target.pos(), idx, Err(field), "") - .compress(), - )), - ty::Kind::Global(idx) => Some(Value::ty({ - let global = &self.tys.globals[idx as usize]; - ty::Id::from(u32::from_ne_bytes( - self.output.code[global.offset as usize..][..4] - .try_into() - .unwrap(), - )) - })), + ty::Kind::Module(idx) => { + match self.find_or_declare(target.pos(), idx, Err(field), "") { + ty::Kind::Global(idx) => self.handle_global(idx), + e => Some(Value::ty(e.compress())), + } + } + ty::Kind::Global(idx) => self.handle_global(idx), e => unimplemented!("{e:?}"), } } diff --git a/hblang/text-prj/main.hb b/hblang/text-prj/main.hb index 85e81a94..f36f2fe8 100644 --- a/hblang/text-prj/main.hb +++ b/hblang/text-prj/main.hb @@ -1,5 +1,5 @@ pkg := @use("pkg.hb"); main := fn(a: int): int { - return pkg.fib(10); + return pkg.fib(pkg.global); } diff --git a/hblang/text-prj/pkg.hb b/hblang/text-prj/pkg.hb index 931098ba..6dd10a5e 100644 --- a/hblang/text-prj/pkg.hb +++ b/hblang/text-prj/pkg.hb @@ -1,3 +1,5 @@ +global := 10; + fib := fn(n: int): int { return n + 1; }