-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Compile-time string builtins require a constant string literal. However, an empty string literal ("") is rejected as “not a constant string”, while a whitespace-only string (" ") is accepted and evaluated as an empty hex bitstring. This indicates the compiler is conflating “missing/non-constant string” with “empty string literal”.
Reproduction
Control: whitespace-only string compiles and produces an empty slice.
Create /tmp/tolk_stringHexToSlice_spaces_ok.tolk:
tolk 1.0
import "@stdlib/common.tolk";
fun onInternalMessage() { return 0; }
@method_id(100)
fun bitsCount(): int {
var s: slice = stringHexToSlice(" "); // hex parser skips spaces -> empty slice
return s.remainingBitsCount();
}
Compile + run:
./artifacts/tolk /tmp/tolk_stringHexToSlice_spaces_ok.tolk > /tmp/tolk_stringHexToSlice_spaces_ok.fif
./artifacts/fift -I artifacts/lib /tmp/tolk_stringHexToSlice_spaces_ok_runner.fifCreate /tmp/tolk_stringHexToSlice_spaces_ok_runner.fif:
"/tmp/tolk_stringHexToSlice_spaces_ok.fif" include <s constant code
100 code 1 runvmx abort"exitcode is not 0" .s cr { drop } depth 1- times
Observed output:
0
Failing case: empty string literal is rejected.
Create /tmp/tolk_stringHexToSlice_empty_rejects.tolk:
tolk 1.0
import "@stdlib/common.tolk";
fun onInternalMessage() { return 0; }
@method_id(100)
fun bitsCount(): int {
var s: slice = stringHexToSlice("");
return s.remainingBitsCount();
}
Compile:
./artifacts/tolk /tmp/tolk_stringHexToSlice_empty_rejects.tolk > /tmp/out.fifObserved:
error: function `stringHexToSlice` requires a constant string, like `stringHexToSlice("some_str")`
Expected behavior
Empty string literals should be treated as valid constant strings. In particular, stringHexToSlice("") should compile and evaluate to the empty slice (the same result as stringHexToSlice(" ")).