Block inputs' types don't appear to ever account for reporter blocks being plugged in #100
Labels
API / interface
Relevant to object structures and interfaces beyond serialization
discussion
Looking for feedback and input
I really hope I'm just missing something here, because this seems to undermine the entire type-safety of the library.
Right now, it seems that the
Block
type is set up such that a block's inputs are always assumed to hold literal values and never any reporter blocks plugged into them. For instance, theoperators_add
block is always assumed to have twoBlockInput.Number
inputs, each of which holds a numeric literal. The possibility that these inputs may also be occupied by other (reporter) blocks doesn't seem to be considered.So far, there are a couple reasons that this has managed to sneak through the API:
BlockInput.Any
, meaning that it handles the case where those inputs are blocks.Block
type is a union ofKnownBlock
andUnknownBlock
. SinceUnknownBlock
is actually just a supertype ofKnownBlock
where the opcode can be any string (including redefining known opcodes) and all inputs areBlockInput.Any
, all code which uses theBlock
type cannot make any assumptions about the "shape" of the block's inputs based on its opcode, and must handle all cases.Even so, I've already found a case where serialization errors out as a result of incorrectly narrowing blocks' inputs based on opcodes: the "change pen (param) by" block cannot be converted if a reporter block is plugged into the menu:
There are probably many more instances of this throughout the codebase. I think there needs to be a major rework of the
Block
class in order to fix this soundness hole, especially if we want to use TypeScript to its full potential. We may want to consider separating inputs and fields the same way Scratch does, so that we can tell which inputs may and may not have blocks plugged into them.The text was updated successfully, but these errors were encountered: