Allow fully-discard constructor parameter dicts

This commit is contained in:
Tony Garnock-Jones 2023-03-06 23:26:34 +01:00
parent 545282be32
commit cbcb692db8
1 changed files with 16 additions and 3 deletions

View File

@ -140,11 +140,24 @@ export function ctor(info: QuasiValueConstructorInfo, ... items: QuasiValue[]):
}
function qLookup(b: Meta.Binding): QuasiValue {
if (ctorArgs.length === 0) {
throw new Error(`Missing dictionary argument to ${defNameStr}`);
let d: QuasiValue;
switch (ctorArgs.length) {
case 0:
// Previously, this was an error:
// throw new Error(`Missing dictionary argument to ${defNameStr}`);
// but I think it actually makes sense to just treat it as a full-on discard.
d = _;
break;
case 1:
d = ctorArgs[0];
break;
default:
throw new Error(`Too many arguments to ${defNameStr}`);
}
const d = ctorArgs[0];
if (defType.kind === 'record' && defType.fields.size !== 1) {
if (d.type === 'discard') {
return d;
}
if (d.type !== 'dict') {
throw new Error(`Dictionary argument needed to ${defNameStr}`);
}