Skip to content

EZC: Type checker implementation #1175

@SchoolyB

Description

@SchoolyB

Type Checker

The type checker is the single biggest missing piece in EZC. It enables:

  • Correct string interpolation with any type (currently broken for string variables)
  • Type mismatch errors with helpful messages
  • Unused variable/import detection
  • Missing return analysis
  • Implicit narrowing warnings
  • "Did you mean?" suggestions (requires symbol table)

Checklist

Core infrastructure

  • Scope/symbol table — nested scopes with variable name → type mappings
  • Type representation — primitives, arrays, maps, structs, enums, functions, void
  • Type registry — register struct/enum types during declaration pass
  • Function signature registry — register function params and return types

Type checking passes

  • Pass 1: Register declarations — collect all struct, enum, and function declarations
  • Pass 2: Check statements — validate types in function bodies

Expression type resolution

  • Literals — int, float, string, char, bool, nil have known types
  • Variables — look up type from scope
  • Binary expressions — validate operand types, determine result type
  • Comparison expressions — operands must be compatible, result is bool
  • Function calls — validate argument types against parameter types, return type resolution
  • Member access — look up struct field types, enum member types
  • Index access — array element type, map value type
  • String interpolation — determine format specifier from resolved expression type

Statement type checking

  • Variable declarations — validate value type matches declared type
  • Assignments — validate value type matches variable type, check mutability
  • Return statements — validate return value types match function signature
  • If conditions — must be boolean
  • For range — iterator variable is int
  • When/is — case values must match switch value type

Integration with codegen

  • Annotate AST nodes with resolved types (side table keyed by node pointer)
  • Codegen reads resolved types for string interpolation format specifiers
  • Codegen reads resolved types for println dispatch

References

  • Go type checker: pkg/typechecker/typechecker.go (9497 lines — the logic to port)
  • Go scope: embedded in typechecker

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestezcEZC compiler tool (EZ → C → native binary)typecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions