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
-
@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
};
-
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
};
-
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
-
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
Overview
Enhance the TypeResolver to support more complete type resolution, enabling semantic lint rules that need to understand and compare types.
What it unlocks
.init())@as()detectionCurrent state
TypeResolver.zigalready provides:resolveNodeType()- resolves AST nodes toTypeInforesolveMethodCall()- finds methods and resolves return typesfindMethodDef()- locates method definitionsModuleGraph- tracks modules and their ASTsWhat's missing
@This()resolution in return typesCurrently, if a method returns
@This(), the resolver returns.unknown. It needs to track the "current container context" during resolution.Type alias following
Common pattern
const Self = @This()is not followed when resolving return types.Type equality comparison
Need to compare if two
TypeInfovalues represent the same semantic type, accounting for:Foo==Foo)Self==@This()== containing type)Generic type instantiation tracking
ArrayList(u8).init()should know it returnsArrayList(u8).Implementation approach
container_contextfield to resolution functions to track the containing type@This()to the container context when availableTypeInfo.semanticEquals()for type comparisonStatus
Not yet committed to. Tracking this so rules that need it have a place to point to.
Related