convex icon indicating copy to clipboard operation
convex copied to clipboard

Should `MultiFn` allow dead code?

Open helins opened this issue 4 years ago • 2 comments

((fn ([a] :first) ([a] :second)) 42)

;; :first

Here we have two different bodies for the same arity and only the former is considered at call. Sounds like it could produces some nasty bugs, the kind of bugs that happen rarely but when they do, they can make you go crazy.

helins avatar Jun 01 '21 16:06 helins

This looks trivial but is actually an undecidable problem given:

  • Destructuring
  • Future possible type constraints
  • Future possibly arbitrary pre-condition code

Possible enhancement to to allow MultiFns to catch :ARGUMENT, :TYPE and :ARITY errors and proceed to try the next body in such cases.

Workaround at the user level is to provide a customer expander / compiler that detects such cases according to the user's preferred logic.

mikera avatar Jun 01 '21 23:06 mikera

I think this is a wontfix directly, but could be addressed in future static analysis tools / off-chain compilers. If we implement on-chain, it would be V2

mikera avatar Jul 02 '21 03:07 mikera