gccrs: Fix typechecking of block expression and labels
gccrs typechecker now correctly handles the context for labels within block expressions.
The gccrs compiler’s typechecker has been updated to correctly handle labels within block expressions. Previously, tail expressions in these blocks ignored the context and incorrectly returned the unit type. This change ensures that the label context is respected, resolving a typechecking issue.
In Details
In TypeCheckExpr::visit within rust-hir-type-check-expr.cc, the handling of block expressions was not respecting the context provided by labels. This resulted in the tail expression of a block always returning unit-type regardless of the context. This patch modifies the logic to properly consider context.label when determining the type of the block's tail expression.
- gccrs
- The Rust front-end for GCC, enabling GCC to compile Rust code.
- typechecking
- The process of verifying that the types of variables and expressions in a program are used in a way that conforms to the language's type system rules.
- block expression
- In Rust (and some other languages), a block is a sequence of statements enclosed in curly braces
{}. The value of the block is the value of its last expression, if any. - unit-type
- In Rust, the
()type, also known as the unit type, is a type that has only one value,(). It is often used to represent the absence of a meaningful value, similar tovoidin C. - HIR
- High-level Intermediate Representation. In gccrs, HIR is a representation of the Rust code after parsing and some initial semantic analysis, used for subsequent compiler passes.