Skip to content

Type resolution infrastructure #22

@mattrobenolt

Description

@mattrobenolt

Overview

Enhance the TypeResolver to support more complete type resolution, enabling semantic lint rules that need to understand and compare types.

What it unlocks

Current state

TypeResolver.zig already provides:

  • resolveNodeType() - resolves AST nodes to TypeInfo
  • resolveMethodCall() - finds methods and resolves return types
  • findMethodDef() - locates method definitions
  • ModuleGraph - tracks modules and their ASTs
  • Basic type representations (primitives, user types, std types, pointers, optionals, etc.)

What's missing

  1. @This() resolution in return types

    Currently, if a method returns @This(), the resolver returns .unknown. It needs to track the "current container context" during resolution.

    const Foo = struct {
        pub fn init() @This() { ... }  // Should resolve to Foo
    };
  2. Type alias following

    Common pattern const Self = @This() is not followed when resolving return types.

    const Foo = struct {
        const Self = @This();
        pub fn init() Self { ... }  // Should resolve to Foo
    };
  3. Type equality comparison

    Need to compare if two TypeInfo values represent the same semantic type, accounting for:

    • Direct matches (Foo == Foo)
    • Alias resolution (Self == @This() == containing type)
    • Cross-module types
  4. Generic type instantiation tracking

    ArrayList(u8).init() should know it returns ArrayList(u8).

Implementation approach

  • Add a container_context field to resolution functions to track the containing type
  • Resolve @This() to the container context when available
  • Build a symbol table for type aliases within containers
  • Implement TypeInfo.semanticEquals() for type comparison

Status

Not yet committed to. Tracking this so rules that need it have a place to point to.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions