Fix error reporting; handle unit like record

This commit is contained in:
Tony Garnock-Jones 2021-03-23 12:16:16 +01:00
parent e187fb83b4
commit c23cbcc60c
1 changed files with 9 additions and 2 deletions

View File

@ -58,7 +58,14 @@ function unconverterForAlternative(
}
return (cs.length === 1) ? cs[0] : seq(`_.merge`, parens(`(a, b) => (a === b) ? a : void 0`, ... cs));
} else {
return unconverterFor(ctx, a.value, src, t);
try {
return unconverterFor(ctx, a.value, src, t);
} catch (e) {
if (e instanceof InsufficientInformationError) {
throw new Error(`Cannot produce unconverter for ${name}: ${e.message}`);
}
throw e;
}
}
}
@ -82,7 +89,7 @@ function unconverterFor(ctx: FunctionContext, p: M.Pattern, src: string, t: Simp
switch (p._variant) {
case 'SimplePattern':
return ((p: M.SimplePattern) => {
if (p._variant !== 'lit' && t.kind === 'record') {
if (p._variant !== 'lit' && (t.kind === 'record' || t.kind === 'unit')) {
throw new InsufficientInformationError(`A Cannot produce unconverter TODO ${src} ${formatItems([renderType(t)])}`);
}
switch (p._variant) {