Fix error reporting; handle unit like record
This commit is contained in:
parent
e187fb83b4
commit
c23cbcc60c
|
@ -58,7 +58,14 @@ function unconverterForAlternative(
|
|||
}
|
||||
return (cs.length === 1) ? cs[0] : seq(`_.merge`, parens(`(a, b) => (a === b) ? a : void 0`, ... cs));
|
||||
} else {
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue