Diagnostic and cause
СсылкаType is not JSON encodable
- Семейство
- topaz
- Этап
- check
- Код
TPZ5533
Причина и условия
json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.
Связанное правило · Type is not JSON encodable →Действия
Project the value into supported JSON data. Encode its data fields instead of passing behavior or opaque host values.
Compiler phase: check.
Compiler explanation: JSON.stringify or a JSON encode path received a type outside the supported deterministic JSON shape.
Message templates. The marker ⟨value⟩ stands for text computed for the reported program.
⟨value⟩is not JSON-encodable, sojson.cannot encode it Sourcestringify
json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.
Type is not JSON encodable
json.stringify requires a JSON-encodable argument type. Passing a function value is rejected with TPZ5533; passing the function's integer result is accepted.
Response
СсылкаProject the value into supported JSON data. Encode its data fields instead of passing behavior or opaque host values.
Reproduction and verification
СсылкаRejected program
Ссылкаimport std.jsonfunction compute() -> int { 1 }let encoded = json.stringify(compute)
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения check. Ненулевой код завершения.
diagnostic-tpz5533 at
example.tpz:3:15
Repaired program
Ссылкаimport std.jsonfunction compute() -> int { 1 }let encoded = json.stringify(compute())
Ожидаемый результат
Ожидаемый результат
Проверка принимает программу. Код завершения 0.