Skip to content

fix List[Int].join crash; support joining int lists#201

Merged
kacy merged 1 commit into
mainfrom
fix/list-join-int
May 23, 2026
Merged

fix List[Int].join crash; support joining int lists#201
kacy merged 1 commit into
mainfrom
fix/list-join-int

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented May 23, 2026

summary

list.join(sep) lowered to pith_list_join, which reads every element as a
C-string pointer. on an Int list that dereferences integers as pointers and
segfaults (found while testing the list-method-syntax PR; it predates that
change and reproduced with the free-function form too).

now an Int-element list lowers to a new pith_list_join_int runtime function
that formats each element as decimal:

[1, 2, 3].join(",")        # -> "1,2,3"
nums.map(fn(x) => x*2).join("|")

String lists are unchanged. element types that join still cannot format
(Float, Bool, structs, ...) are now a clear compile error instead of a
crash.

how

  • runtime: new pith_list_join_int formats i64 elements with a separator;
    registered in runtime-abi/runtime_functions.txt
  • ir emitter: when join's receiver has an Int element kind, emit
    list_join_int instead of list_join; added to the string-returning method
    set so its result type is String
  • checker: join now requires String or Int elements, reporting E219
    otherwise

what was tested

  • new regression tests/cases/test_list_join_int.pith (separators, empty list,
    single element, negatives, map-then-join, and a String list)
  • new invalid-checker case invalid_join_non_string asserting E219 on a
    List[Float] join
  • full suite: regressions (94), invalid checker (14), examples native + self
    hosted (83 each), bootstrap fixed point — all 0 failures

list.join lowered to pith_list_join, which reads every element as a C string
pointer. for an Int list that dereferences integers as pointers and segfaults.

now an Int-element list lowers to a new pith_list_join_int runtime function
that formats each element as decimal:

    [1, 2, 3].join(",")   # -> "1,2,3"

String lists are unchanged. element types that join still cannot format
(Float, Bool, structs, ...) are now rejected by the checker with a clear
error instead of crashing at runtime.
@kacy kacy merged commit ef2b95b into main May 23, 2026
2 checks passed
@kacy kacy deleted the fix/list-join-int branch May 23, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant