fix List[Int].join crash; support joining int lists#201
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
list.join(sep)lowered topith_list_join, which reads every element as aC-string pointer. on an
Intlist that dereferences integers as pointers andsegfaults (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 newpith_list_join_intruntime functionthat formats each element as decimal:
Stringlists are unchanged. element types thatjoinstill cannot format(
Float,Bool, structs, ...) are now a clear compile error instead of acrash.
how
pith_list_join_intformats i64 elements with a separator;registered in
runtime-abi/runtime_functions.txtjoin's receiver has anIntelement kind, emitlist_join_intinstead oflist_join; added to the string-returning methodset so its result type is
Stringjoinnow requiresStringorIntelements, reportingE219otherwise
what was tested
tests/cases/test_list_join_int.pith(separators, empty list,single element, negatives, map-then-join, and a String list)
invalid_join_non_stringassertingE219on aList[Float]joinhosted (83 each), bootstrap fixed point — all 0 failures