wcc/check: #14 reject def-global scalar str index (silent segfault) (both stages)
def S:str = "hi"; S[0] silently segfaulted: a def is a compile-time constant, never materialized as DATA (unlike let), so indexing it emitted an unbacked main.S(SB) reference -> cstage ran into frame garbage, wwstage link-failed. str[i] itself is valid ww (a deliberate Go-like str[i]->u8 byte-index that lib/strings compare/dup depend on), so the fix is narrow: the N_INDEX TY_STR arm now rejects an index whose operand is a bare SK_DEF scalar-str symbol, both stages -- 'cannot index a def-constant str; bind it to a let'. INDEX-ONLY: len(S) and &S are already loud, and a def's .len/.ptr field reads (the load-bearing w6l INTERP) are N_DOT, a different arm, and stay valid. A rule-9 WHY-comment records str[i]->u8 as a sanctioned divergence from Hare's strings.toutf8. The full make-it-work fold (len(S)->2, S[0]->byte) is deferred (#16). byte-id 990-997 8/8. test/wcc/821 table-driven.
This commit is contained in:
7
Makefile
7
Makefile
@@ -249,6 +249,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
|
||||
$(BIN)/test_def_arr_len \
|
||||
$(BIN)/test_def_str_table \
|
||||
$(BIN)/test_arr_zero_vs_infer \
|
||||
$(BIN)/test_def_str_index_reject \
|
||||
$(BIN)/test_slice_str_global_zero \
|
||||
$(BIN)/test_slice_literal_global \
|
||||
$(BIN)/test_global_arr_elem_field \
|
||||
@@ -651,6 +652,12 @@ $(BIN)/test_arr_ptr_global: test/wcc/818_arr_ptr_global.c $(BIN)/ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_def_str_index_reject: test/wcc/821_def_str_index_reject.c $(BIN)/ww \
|
||||
$(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
$(LIB)/libwwrt.a | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN)/test_def_arr_infer_len: test/wcc/814_def_arr_infer_len.c $(BIN)/ww \
|
||||
$(BIN)/w6c $(BIN)/w6a $(BIN)/w6l \
|
||||
$(BIN)/ww_ww $(BIN)/w6c_ww $(BIN)/w6a_ww $(BIN)/w6l_ww \
|
||||
|
||||
Reference in New Issue
Block a user