Jacajack / hdl

A proof-of-concept, Rust-inspired, declarative hardware description language optimized for RTL coding
MIT License
17 stars 1 forks source link

[panic] Unary minus on boolean causes `num_consistency_check()` to fail #354

Closed Jacajack closed 11 months ago

Jacajack commented 11 months ago

Input

// It's a cute little one
module X {}
impl X {
    uint x = -(0 == 0);
}
[2023-11-22T19:40:56Z DEBUG hdllang::core::numeric_constant] Created numeric constant: NumericConstant { value: -1, width: Some(1), signed: Some(false), base: Some(Boolean) }
thread 'main' panicked at 'assertion failed: num.consistency_check()', hdllang/src/core/numeric_constant.rs:71:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/panicking.rs:117:5
   3: hdllang::core::numeric_constant::NumericConstant::new_from_unary
             at ./hdllang/src/core/numeric_constant.rs:71:3
   4: hdllang::parser::ast::expression::Expression::evaluate
             at ./hdllang/src/parser/ast/expression.rs:489:10
   5: hdllang::parser::ast::variable_definition::VariableDefinition::analyze
             at ./hdllang/src/parser/ast/variable_definition.rs:148:21
   6: hdllang::parser::ast::module_implementation_statement::ModuleImplementationStatement::first_pass
             at ./hdllang/src/parser/ast/module_implementation_statement.rs:60:5
   7: hdllang::parser::ast::top_definition::module_implementation::ModuleImplementation::first_pass
             at ./hdllang/src/parser/ast/top_definition/module_implementation.rs:33:6
   8: hdllang::analyzer::semantical_analyzer::first_pass
             at ./hdllang/src/analyzer/semantical_analyzer.rs:204:2
   9: hdllang::analyzer::semantical_analyzer::SemanticalAnalyzer::compile_and_elaborate
             at ./hdllang/src/analyzer/semantical_analyzer.rs:89:5
  10: hdllang::utils::elaborate
             at ./hdllang/src/utils.rs:239:2
  11: hdl::main
             at ./src/main.rs:123:4
  12: core::ops::function::FnOnce::call_once
             at /rustc/a41fc00eaf352541008965fec0dee811e44373b3/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Jacajack commented 11 months ago

Possibly related: #343

Jacajack commented 11 months ago

Also fails:

module X {}
impl X {
    int x = -0;
}