Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/codegen/expressions/access/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
parseMapTypeString,
canonicalTypeToLlvm,
} from "../../infrastructure/type-system.js";
import type { ResolvedType } from "../../infrastructure/type-system.js";
import type {
IStringGenerator,
IMapGenerator,
Expand Down Expand Up @@ -203,6 +204,7 @@ export interface MemberAccessGeneratorContext {
classGenIsStaticField(className: string, fieldName: string): boolean;
classGenGetStaticFieldType(className: string, fieldName: string): string;
mangleUserName(name: string): string;
resolveExpressionTypeRich(expr: Expression): ResolvedType | null;
}

export type MemberAccessHandlerFn = (
Expand Down Expand Up @@ -2221,6 +2223,16 @@ export class MemberAccessGenerator {
private getObjectArrayElementInfo(
arrayExpr: Expression,
): { keys: string[]; types: string[]; tsTypes: string[] } | null {
// Canonical path (P3b): delegate to TypeInference.resolveExpressionTypeRich.
// Fires when the object resolves to an array of an interface/class whose
// fields we know — covers method-chain and call returns that the legacy
// branches below partially miss. Legacy branches remain for shapes not yet
// covered by the canonical resolver.
const rich = this.ctx.resolveExpressionTypeRich(arrayExpr);
if (rich && rich.arrayDepth > 0 && rich.fields) {
return { keys: rich.fields.keys, types: rich.fields.types, tsTypes: rich.fields.tsTypes };
}

if (arrayExpr.type === "member_access") {
const memberAccess = arrayExpr as MemberAccessNode;
const memberAccessObjBase = memberAccess.object as ExprBase;
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/llvm-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ export class LLVMGenerator extends BaseGenerator implements IGeneratorContext {

public emitError(message: string, loc?: SourceLocation, suggestion?: string): never {
this.diagnostics.error(message, loc, suggestion);
const errs = this.diagnostics.getErrors();
const last = errs[errs.length - 1];
const output = this.diagnostics.formatDiagnostic(last);
const output = this.diagnostics.formatDiagnostic(
this.diagnostics.getErrors()[this.diagnostics.getErrors().length - 1],
);
process.stderr.write(output);
process.exit(1);
}
Expand Down
Loading