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

Investigate Task.await behaviour in rocci-bird #6656

Open
lukewilliamboswell opened this issue Apr 21, 2024 · 1 comment
Open

Investigate Task.await behaviour in rocci-bird #6656

lukewilliamboswell opened this issue Apr 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@lukewilliamboswell
Copy link
Collaborator

lukewilliamboswell commented Apr 21, 2024

Investigate why the two below are not equal.

The only change is the line collided <- collidedTask |> Task.await to Task.await collidedTask \collided ->

    List.walk collisionPoints (Task.ok Bool.false) \collidedTask, { x, y } ->
        collided <- collidedTask |> Task.await
        if collided then
            Task.ok Bool.true
        else
            point = {
                x: Num.toU8 (playerX + x),
                y: Num.toU8 (playerY + y),
            }
            color = W4.getPixel! point
            Task.ok (color != Color1)

    List.walk collisionPoints (Task.ok Bool.false) \collidedTask, { x, y } ->
        Task.await collidedTask \collided ->
            if collided then
                Task.ok Bool.true
            else
                point = {
                    x: Num.toU8 (playerX + x),
                    y: Num.toU8 (playerY + y),
                }
                color = W4.getPixel! point
                Task.ok (color != Color1)
── TYPE MISMATCH in examples/rocci-bird.roc ────────────────────────────────────

This expression is used in an unexpected way:

407│>      List.walk collisionPoints (Task.ok Bool.false) \collidedTask, { x, y } ->
408│>          Task.await collidedTask \collided ->
409│>              if collided then
410│>                  Task.ok Bool.true
411│>              else
412│>                  point = {
413│>                      x: Num.toU8 (playerX + x),
414│>                      y: Num.toU8 (playerY + y),
415│>                  }
416│>                  color = W4.getPixel! point
417│>                  Task.ok (color != Color1)

This walk call produces:

    InternalTask.Task Bool *

But you are trying to use it as:

    {}a

Tip: Type comparisons between an opaque type are only ever equal if
both types are the same opaque type. Did you mean to create an opaque
type by wrapping it? If I have an opaque type Age := U32 I can create
an instance of this opaque type by doing @Age 23.


── TYPE MISMATCH in examples/rocci-bird.roc ────────────────────────────────────

Something is off with the body of the onScreenCollided definition:


  

This Task.ok call produces:

    Task {} []

But the type annotation on onScreenCollided says it should be:

    Task Bool []

────────────────────────────────────────────────────────────────────────────────
@lukewilliamboswell lukewilliamboswell changed the title Investigate Task.await behaviour in bocci-bird Investigate Task.await behaviour in rocci-bird Apr 21, 2024
@lukewilliamboswell
Copy link
Collaborator Author

Update - as a workaround in bocci-bird I've pull the closure out into a helper and that has resolved the issue. But this still seems like an interesting edge case.

@lukewilliamboswell lukewilliamboswell added the bug Something isn't working label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant