Commit 86f0ecad
86f0ecad079fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Type poly << as poly so shift and append stay consistent
x << y on a poly receiver is ambiguous: Integer#<< (bit shift) vs Array#push
(append). The runtime sp_poly_shl already dispatches on the value's tag and
returns a boxed result either way -- a boxed int for a shift, the array for an
append -- so the static type is simply poly. A downstream bitwise op coerces
the boxed int back via sp_poly_to_i, and an append keeps its (boxed) array.
Previously inference left poly << unknown, so (@data << 1) & 0xff (with a
poly-typed register) failed to type the & receiver. Typing it poly and adding
the expression-context sp_poly_shl emit fixes that without disturbing the
append form, which already returns poly.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 86f0ecad079f
- Parent
- bfc8ed7bf537
src/analyze_infer.cmodifiedView file
(!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^") || !strcmp(name, "<<") || !strcmp(name, ">>"))) return TY_INT; /* poly recv bitwise op: result is int (sp_poly_to_i applied). `<<` is left out because it is ambiguous on a poly (Integer#<< shift vs Array#push append), and the append form must keep its array result type. */ /* poly recv bitwise op: result is int (sp_poly_to_i applied). */ if (recv >= 0 && argc == 1 && rt == TY_POLY && (!strcmp(name, ">>") || !strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^"))) return TY_INT; /* poly recv `<<` is ambiguous (Integer#<< shift vs Array#push append); the runtime sp_poly_shl dispatches on the tag and returns a boxed result either way, so the static type is poly. A downstream bitwise op coerces it back to int, and an append keeps its (boxed) array -- both stay consistent. */ if (recv >= 0 && argc == 1 && rt == TY_POLY && !strcmp(name, "<<")) return TY_POLY; /* boolean &/|/^ */ if (recv >= 0 && argc == 1 && rt == TY_BOOL && (!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^")))src/codegen_call.cmodifiedView file
Loading diff…