No Encode/Decode for Nat

This commit is contained in:
Ayaz Hafiz 2023-01-27 17:16:10 -06:00
parent 99050956d3
commit 572a666780
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 131 additions and 14 deletions

View file

@ -13,8 +13,8 @@ use roc_module::symbol::Symbol;
use roc_problem::Severity;
use roc_region::all::{LineInfo, Region};
use roc_solve_problem::{
NotDerivableContext, NotDerivableDecode, NotDerivableEq, TypeError, UnderivableReason,
Unfulfilled,
NotDerivableContext, NotDerivableDecode, NotDerivableEncode, NotDerivableEq, TypeError,
UnderivableReason, Unfulfilled,
};
use roc_std::RocDec;
use roc_types::pretty_print::{Parens, WILDCARD};
@ -371,7 +371,29 @@ fn underivable_hint<'b>(
])),
])))
}
NotDerivableContext::Encode(reason) => match reason {
NotDerivableEncode::Nat => {
Some(alloc.note("").append(alloc.concat([
alloc.reflow("Encoding a "),
alloc.type_str("Nat"),
alloc.reflow(" is not supported. Consider using a fixed-sized unsigned integer, like a "),
alloc.type_str("U64"),
alloc.reflow("instead."),
])))
}
},
NotDerivableContext::Decode(reason) => match reason {
NotDerivableDecode::Nat => {
Some(alloc.note("").append(alloc.concat([
alloc.reflow("Decoding to a "),
alloc.type_str("Nat"),
alloc.reflow(" is not supported. Consider decoding to a fixed-sized unsigned integer, like "),
alloc.type_str("U64"),
alloc.reflow(", then converting to a "),
alloc.type_str("Nat"),
alloc.reflow(" if needed."),
])))
}
NotDerivableDecode::OptionalRecordField(field) => {
Some(alloc.note("").append(alloc.concat([
alloc.reflow("I can't derive decoding for a record with an optional field, which in this case is "),