Allow fully-discard constructor parameter dicts
This commit is contained in:
parent
545282be32
commit
cbcb692db8
|
@ -140,11 +140,24 @@ export function ctor(info: QuasiValueConstructorInfo, ... items: QuasiValue[]):
|
||||||
}
|
}
|
||||||
|
|
||||||
function qLookup(b: Meta.Binding): QuasiValue {
|
function qLookup(b: Meta.Binding): QuasiValue {
|
||||||
if (ctorArgs.length === 0) {
|
let d: QuasiValue;
|
||||||
throw new Error(`Missing dictionary argument to ${defNameStr}`);
|
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 (defType.kind === 'record' && defType.fields.size !== 1) {
|
||||||
|
if (d.type === 'discard') {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
if (d.type !== 'dict') {
|
if (d.type !== 'dict') {
|
||||||
throw new Error(`Dictionary argument needed to ${defNameStr}`);
|
throw new Error(`Dictionary argument needed to ${defNameStr}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue