Commit c593be1f

c593be1fdfb9Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Fix ivar write nodes as expressions and Array.new(n,obj)

  • Add InstanceVariableWriteNode/OrWriteNode/AndWriteNode/OperatorWriteNode to infer_uncached so type propagation works for chained writes
  • Add InstanceVariableWriteNode as expression in emit_expr with empty hash/array promotion and poly-boxing
  • Add InstanceVariableOrWriteNode/AndWriteNode to both emit_expr and compile_stmt
  • Fix Array.new(n, fill) for poly-array fill (object type)

514 -> 517 pass

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
c593be1fdfb9
Parent
9be3351880cc

src/analyze.cmodifiedView file

@@ -1113,6 +1113,18 @@
11131113 if (!strcmp(ty, "LambdaNode")) return TY_PROC;
11141114 /* an assignment expression evaluates to the assigned value */
11151115 if (!strcmp(ty, "LocalVariableWriteNode")) return infer_type(c, nt_ref(nt, id, "value"));
1116+ if (!strcmp(ty, "InstanceVariableWriteNode") ||
1117+ !strcmp(ty, "InstanceVariableOrWriteNode") ||
1118+ !strcmp(ty, "InstanceVariableAndWriteNode") ||
1119+ !strcmp(ty, "InstanceVariableOperatorWriteNode")) {
1120+ /* expression evaluates to the ivar slot's type (same as a read) */
1121+ const char *nm = nt_str(nt, id, "name");
1122+ Scope *s = comp_scope_of(c, id);
1123+ if (s->class_id < 0) return infer_type(c, nt_ref(nt, id, "value"));
1124+ ClassInfo *ci = &c->classes[s->class_id];
1125+ int iv = nm ? comp_ivar_index(ci, nm) : -1;
1126+ return iv >= 0 ? ci->ivar_types[iv] : TY_UNKNOWN;
1127+ }
11161128 if (!strcmp(ty, "LocalVariableOperatorWriteNode")) {
11171129 const char *nm2 = nt_str(nt, id, "name");
11181130 Scope *s2 = comp_scope_of(c, id);