Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing if statement in example #78

Open
Chadtech opened this issue Oct 6, 2018 · 1 comment
Open

Error parsing if statement in example #78

Chadtech opened this issue Oct 6, 2018 · 1 comment
Labels
bug parsing Relates to parsing code or examples

Comments

@Chadtech
Copy link

Chadtech commented Oct 6, 2018

Hi,

I am trying to incorporate elm-verify-examples and so far its going pretty good.

However I do have one example which is having a problem. Here my is my function and its documentation..

{-| The `unfoldr` function is "dual" to `foldr`. `foldr` reduces a list to a summary value, `unfoldr` builds a list from a seed. The function takes a function and a starting element. It applies the function to the element. If the result is `Just (a, b)`, `a` is accumulated and the function is applied to `b`. If the result is `Nothing`, the list accumulated so far is returned.

    subtractOneUntilZero : Int -> Maybe (Int, Int)
    subtractOneUntilZero i =
        if i /= 0 then
            Just (i, i - 1)

        else
            Nothing

    unfoldr subtractOneUntilZero 5
    --> [ 5, 4, 3, 2, 1 ]

-}
unfoldr : (b -> Maybe ( a, b )) -> b -> List a
unfoldr f seed =
    case f seed of
        Nothing ->
            []

        Just ( a, b ) ->
            a :: unfoldr f b

When I run elm-verify-example on this function I get this error..

Ct:list-extra Chadtech$ elm-verify-examples
-- PARSE ERROR - /Users/Chadtech/code/list-extra/tests/VerifyExamples/List/Extra/Unfoldr0.elm

Something went wrong while parsing an `if` expression in subtractOneUntilZero's
definition.

15|     if i /= 0 then
16|         Just (i, i - 1)
17| 
18| 
19| 
20| spec0 : Test.Test
    ^
I was expecting:

  - an `else` branch. An `if` must handle both possibilities.
  - an argument, like `name` or `total`
  - the end of that `if`. Maybe you forgot some code? Or maybe the body of
    `subtractOneUntilZero` needs to be indented?

I can get around this error by just removing the empty line between the if and else..

        if i /= 0 then
            Just (i, i - 1)
        else
            Nothing
@MethodGrab
Copy link

This also applies to case statements.

@gampleman gampleman added bug parsing Relates to parsing code or examples labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug parsing Relates to parsing code or examples
Projects
None yet
Development

No branches or pull requests

3 participants