If you're creating a block to compare two variables, like this:
then that should be pretty straight forward, and you should be able to implement this in a subclass of
FieldVariable using a similar technique (field validators) as is used in the
field-dpendent-dropdown plugin.
On the other hand, if you want a block that can compare an arbitrary value to a variable, like this:
then this will be rather more difficult. In fact, it's not in general guaranteed to even be possible to ascertain the value of the expression on the left hand side of the comparison: if the user can connect a
procedures_callreturn block to the input then determining the type of the returned value might be equivalent to solving
the halting problem: the only general way to know is to generate the code and run it, and hope that the procedure eventually terminates and returns a value…
(Of course if you are using typed variables you may well also have typed procedure returns, and if so (and you're willing to ignore the possibility that the procedure never returns) then it should be possible to do reliable static analysis of the type of the connected expression. It will still be a non-trivial, though, because you'll need to be able to analyse any combination of connected value blocks.)
A reasonable compromise might be to attempt to do some limited static analysis of the connected value expression—say, by seeing if the block directly connected has a defined type for its output—and showing all available variables if not.
Best wishes,
Christopher