From cbcb692db8375e93fa15ae441e58f7d64aa45e9b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 6 Mar 2023 23:26:34 +0100 Subject: [PATCH] Allow fully-discard constructor parameter dicts --- packages/core/src/runtime/quasivalue.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/core/src/runtime/quasivalue.ts b/packages/core/src/runtime/quasivalue.ts index ae4a4b7..8b4c568 100644 --- a/packages/core/src/runtime/quasivalue.ts +++ b/packages/core/src/runtime/quasivalue.ts @@ -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}`); }