You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that it's the return value in a pattern match
Get the expression inside the case...of
Recursively find all the references from that expression to other functions or values and build up a tree of function dependencies
If any of the leaves of the tree end with something that isn't a literal value then the rule fails
Run an interpreter that starts from the leaves to compute the final value inside the case...of*. Here's a talk showing how that can be done https://www.youtube.com/watch?v=afMD-hkWPsQ
If the value computed doesn't lead to unreachableCase then the rule passes, otherwise it fails.
*Since we are running an interpreter, we can count how many steps we've taken and deterministically timeout to prevent getting caught in an endless loop. The deterministic part is important as it prevents this rule from passing on your dev machine and then failing during CI.
I've started on a proof of concept for this idea using elm-script instead of elm-review for collecting Elm modules. My experience from working on this so far is that I think it is complicated enough that it's better to have as a stand alone tool rather than have it as an elm-review rule.
What the rule should do:
This rule checks if a function called
unreachableCase
really is unreachable. The function is defined asThe use for this is to avoid having to deal with type variants that should never occur. For example
This is essentially a generalization of https://jfmengels.net/safe-unsafe-operations-in-elm/
How I think this rule will work:
unreachableCase
function callcase...of
case...of
*. Here's a talk showing how that can be done https://www.youtube.com/watch?v=afMD-hkWPsQunreachableCase
then the rule passes, otherwise it fails.*Since we are running an interpreter, we can count how many steps we've taken and deterministically timeout to prevent getting caught in an endless loop. The deterministic part is important as it prevents this rule from passing on your dev machine and then failing during CI.
Example of things the rule would report:
Here the
unreachableCase
isn't inside a pattern match. While this situation probably could be handled, I don't see any value in supporting this.Here
longRunningComputation
will eventually returnJust
but it takes too many steps so the rule times out and fails.Example of things the rule would not report:
I am looking for:
The text was updated successfully, but these errors were encountered: