Skip to content

Conversation

@CMI-James
Copy link

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).

Benefits

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

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 dev 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
@SurfingBowser
Copy link
Contributor

Please confirm you have read this contributor guide and followed the instructions. @CMI-James

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