diff --git a/src/end-to-end.test.ts b/src/end-to-end.test.ts index 0516888..afdf125 100644 --- a/src/end-to-end.test.ts +++ b/src/end-to-end.test.ts @@ -234,6 +234,17 @@ testCases(endToEnd, code => code)('end-to-end tests', [ assert.deepEqual(typeof output.value['value'], 'string') }, ], + [ + `{@runtime context => + :identity(:context).program.start_time + }`, + output => { + if (either.isLeft(output)) { + assert.fail(output.value.message) + } + assert(typeof output.value === 'string') + }, + ], [ `{@runtime context => :context.environment.lookup(PATH) diff --git a/src/language/compiling/semantics/keyword-handlers/index-handler.ts b/src/language/compiling/semantics/keyword-handlers/index-handler.ts index c3ef987..e4b4f60 100644 --- a/src/language/compiling/semantics/keyword-handlers/index-handler.ts +++ b/src/language/compiling/semantics/keyword-handlers/index-handler.ts @@ -4,6 +4,7 @@ import type { ElaborationError } from '../../../errors.js' import { applyKeyPathToSemanticGraph, asSemanticGraph, + containsAnyUnelaboratedNodes, keyPathFromObjectNodeOrMolecule, readIndexExpression, stringifyKeyPathForEndUser, @@ -17,20 +18,31 @@ export const indexKeywordHandler: KeywordHandler = ( expression: Expression, _context: ExpressionContext, ): Either => - either.flatMap(readIndexExpression(expression), ({ object, query }) => - either.flatMap(keyPathFromObjectNodeOrMolecule(query), keyPath => - option.match( - applyKeyPathToSemanticGraph(asSemanticGraph(object), keyPath), - { - none: () => - either.makeLeft({ - kind: 'invalidExpression', - message: `property \`${stringifyKeyPathForEndUser( - keyPath, - )}\` not found`, - }), - some: either.makeRight, - }, - ), + either.flatMap(readIndexExpression(expression), indexExpression => + either.flatMap( + keyPathFromObjectNodeOrMolecule(indexExpression.query), + keyPath => { + if (containsAnyUnelaboratedNodes(indexExpression.object)) { + // The object isn't ready, so keep the @index unelaborated. + return either.makeRight(indexExpression) + } else { + return option.match( + applyKeyPathToSemanticGraph( + asSemanticGraph(indexExpression.object), + keyPath, + ), + { + none: () => + either.makeLeft({ + kind: 'invalidExpression', + message: `property \`${stringifyKeyPathForEndUser( + keyPath, + )}\` not found`, + }), + some: either.makeRight, + }, + ) + } + }, ), )