capy-language / capy

🍊 A statically typed, compiled programming language, largely inspired by Jai, Odin, and Zig.
Apache License 2.0
64 stars 4 forks source link

bug in hir type inference leading to accessing invalid index in Arena #4

Closed lenawanel closed 1 year ago

lenawanel commented 1 year ago

trying to compile the following: m::(){y:^mutx2{;y= results in the compiler panicking backtrace:

   0: rust_begin_unwind
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/panicking.rs:619:5
   1: core::panicking::panic_fmt
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/core/src/panicking.rs:127:5
   3: core::option::Option<T>::unwrap
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/core/src/option.rs:935:21
   4: <la_arena::map::ArenaMap<la_arena::Idx<V>,T> as core::ops::index::Index<la_arena::Idx<V>>>::index
             at /home/lena/.cargo/registry/src/index.crates.io-6f17d22bba15001f/la-arena-0.2.1/src/map.rs:61:9
   5: hir::body::Bodies::range_for_expr
             at ./crates/hir/src/body.rs:1101:25
   6: hir_ty::ctx::<impl hir_ty::InferenceCtx>::get_mutability
             at ./crates/hir_ty/src/ctx.rs:347:33
   7: hir_ty::ctx::<impl hir_ty::InferenceCtx>::infer_stmt
             at ./crates/hir_ty/src/ctx.rs:496:28
   8: hir_ty::ctx::<impl hir_ty::InferenceCtx>::infer_expr
             at ./crates/hir_ty/src/ctx.rs:989:21
   9: hir_ty::ctx::<impl hir_ty::InferenceCtx>::finish_body_unknown
             at ./crates/hir_ty/src/ctx.rs:108:9
  10: hir_ty::ctx::<impl hir_ty::InferenceCtx>::finish_body_known
             at ./crates/hir_ty/src/ctx.rs:89:27
  11: hir_ty::InferenceCtx::get_function_signature
             at ./crates/hir_ty/src/lib.rs:383:21
  12: hir_ty::InferenceCtx::finish
             at ./crates/hir_ty/src/lib.rs:279:21
  13: capy::compile_file
             at ./crates/capy/src/main.rs:261:39
  14: capy::main
             at ./crates/capy/src/main.rs:109:5
lenawanel commented 1 year ago

the crashing input can be prettied up to sth like

func::() {
    y:^usize;
    y = 0;
}