Skip to content

Arrays of type Array Unit are always empty #23

Closed

Description

@sarahnya

Since unit is being represented as nil in the generated lua, all arrays of type Array Unit are treated as empty.

minimal example:

module Main where

import Prelude
import Effect (Effect)
import Effect.Console (logShow)
import Data.Array (length)

main :: Effect Unit
main = logShow $ length [unit, unit, unit]

generates

local M = {}
M.Data_Unit_foreign = { unit = nil }
return (function(s) return function() print(s) end end)((function(n) return tostring(n) end)((function(xs) return #xs end)({
  [1] = M.Data_Unit_foreign.unit,
  [2] = M.Data_Unit_foreign.unit,
  [3] = M.Data_Unit_foreign.unit
})))()

and outputs 0 when run.

Any expression that uses the array implementation of guard will be affected by this.

Activity

  1. sarahnya commented on Apr 24, 2024

    @sarahnya
    Author
  2. sarahnya commented on Apr 24, 2024

    @sarahnya
    Author

    I think unit being represented with nil will also cause Record.Unsafe.unsafeHas to return false for fields with type Unit.

  3. changed the title [-]Lists of type [Unit] are always empty[/-] [+]Arrays of type `Array Unit` are always empty[/+] on Apr 25, 2024
  4. Unisay commented on Apr 25, 2024

    @Unisay
    Collaborator

    This is a good find too!

    Thanks for reporting,
    I will be looking at fixing this bug later today.

  5. self-assigned this
    on Apr 25, 2024
  6. Unisay commented on Apr 25, 2024

    @Unisay
    Collaborator

    Should be fixed now: I've changed the representation of Data.Unit from nil to {}, make sure you use the latest package set with "prelude" v7.2.0.

  7. sarahnya commented on Apr 25, 2024

    @sarahnya
    Author

    That fixed it ty!~ I did find another unrelated issue again while testing that this one is fixed but I'll open another issue for that in just a bit. (or maybe just submit a pull request seems like a simple issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions