Skip to content

Conversation

@CMI-James
Copy link

@CMI-James CMI-James commented Jan 23, 2026

Description

Closes #72

Changes proposed

What were you told to do?

I was tasked with implementing Error Type Poisoning to prevent cascading errors in the type checker. This involved adding a TypeInfoKind::Error variant similar to rustc's TyKind::Error and updating the type checker to gracefully handle these error types.

What did I do?

Implemented TypeInfoKind::Error

  • Added Error variant to the TypeInfoKind enum in core/type-checker/src/type_info.rs.
  • Updated Display implementation to show {unknown} for error types.
  • Added is_error() helper method to TypeInfo.
  • Updated substitute and has_unresolved_params to handle Error variants neutrally.

Updated Type Checker Logic

  • Modified core/type-checker/src/type_checker.rs to use TypeInfoKind::Error for type poisoning.
  • Updated infer_expression for Identifier, Struct initialization, MemberAccess, TypeMemberAccess, and FunctionCall to return TypeInfoKind::Error upon lookup failure instead of None or continuing with invalid types.
  • Updated type mismatch checks in Statement::Assign, Statement::Return, Statement::If, Statement::Loop, and others to suppress errors if either the expected or found type is Error.
  • Updated Expression::ArrayIndexAccess, Expression::PrefixUnary, and Expression::Binary to propagate Error types and suppress secondary errors (e.g., "expected array type" when the array expression itself failed).

Added Tests

  • Created tests/src/type_checker/error_type_poisoning_tests.rs with comprehensive tests covering:
    • TypeInfoKind::Error variant behavior (is_error(), Display, substitute, has_unresolved_params)
    • Cascading error suppression (undeclared variables, undefined structs, undefined functions, binary/unary operations, conditions)
    • Error propagation through assignments, struct initialization, chained member access, method calls, function arguments
    • Error types in complex expressions (nested binary, array literals, conditionals, assertions)
    • Error type equality

Benefits

  • Prevents cascading errors when a type lookup fails.
  • Allows type checking to continue more gracefully.
  • Aligns with rustc's error handling model.

AI Disclosure

AI tools (Claude) were used to assist with the following parts of this implementation:

AI-generated code (reviewed and tested before submission):

  • core/type-checker/src/type_info.rs: Added TypeInfoKind::Error variant, is_error() method, Display match arm for Error, and handling in substitute/has_unresolved_params
  • core/type-checker/src/type_checker.rs: Updated type mismatch checks to skip errors when either type is Error, modified infer_expression branches to return TypeInfoKind::Error on lookup failures
  • tests/src/type_checker/error_type_poisoning_tests.rs: AI assisted with test structure and test case implementation

Human contributions:

  • Overall design decision to use rustc-style error poisoning
  • Review and validation of all generated code
  • Testing the implementation against the existing test suite

Check List (Check all the applicable boxes)

🚨Please review the contribution guideline for this repository.

  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the main branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

Screenshot 2026-01-22 at 13 49 02

- Add TypeInfoKind::Error variant to represent unresolved or invalid types
- Update TypeChecker to gracefully handle TypeInfoKind::Error by suppressing cascading errors
- Update expression inference (Identifier, Struct, MemberAccess, FunctionCall, etc.) to return Error type on failure instead of None/cascading
- Prevent spurious type mismatch errors when one of the types is Error
…soning)

- Add tests for TypeInfoKind::Error variant behavior (is_error, Display, substitute, has_unresolved_params)
- Add tests for cascading error suppression with undeclared variables, undefined structs/functions
- Add tests for error propagation through assignments, member access, method calls, function arguments
- Add tests for error types in complex expressions (binary ops, arrays, conditionals)
- Register error_type_poisoning_tests module in mod.rs
@SurfingBowser
Copy link
Contributor

As pointed out in the contributor guide

State clearly in the PR description which parts of the code were generated by AI tools

@CMI-James
Copy link
Author

@SurfingBowser updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider Error Type Poisoning

2 participants