From aaee2c33c87fe1a6f7cb2fcce55df232ccff9d2c Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 1 Jul 2024 23:39:32 -0400 Subject: [PATCH] Use Sequence lengths when determining validity for connections --- src/renderer/helpers/canConnect.ts | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/renderer/helpers/canConnect.ts b/src/renderer/helpers/canConnect.ts index d1ba1bb28..4846ab66e 100644 --- a/src/renderer/helpers/canConnect.ts +++ b/src/renderer/helpers/canConnect.ts @@ -85,6 +85,37 @@ export const canConnect = ( ); } + const outputSequenceType = sourceFn.outputSequence.get(sourceOutputId); + if (outputSequenceType !== undefined) { + const schema = targetSchema; + const input = schema.inputs.find((i) => i.id === targetInputId)!; + + const inputSequenceType = targetFn.inputSequence.get(targetInputId); + if (inputSequenceType) { + const inputSequenceTypeNotNull = withoutNull(inputSequenceType); + + const error = simpleError(outputSequenceType, inputSequenceTypeNotNull); + if (error) { + return invalid( + `Input ${input.label} requires ${error.definition} but would be connected with ${error.assigned}.` + ); + } + + const traceTree = generateAssignmentErrorTrace( + outputSequenceType, + inputSequenceTypeNotNull + ); + if (traceTree) { + const trace = printErrorTrace(traceTree); + return invalid( + `Input ${ + input.label + } cannot be connected with an incompatible value. ${trace.join(' ')}` + ); + } + } + } + // Iterator lineage check const sourceLineage = chainLineage.getOutputLineage(sourceHandle); const lineageValid = checkAssignedLineage(