Skip to content

ObjectUpdate seems to need deep copy #53

Closed
@opyapeus

Description

@opyapeus

It seems that object values are overwritten by shallow copy.
https://github.com/andyarvanitis/purescript-native/blob/golang/src/CodeGen/IL.hs#L183

I don't have a pr, but for now I just report.
I noticed that during my recent work.
https://github.com/opyapeus/psimp

Example

module Main where

import Prelude
import Effect (Effect)
import Effect.Console (log)

-- ObjectUpdate
passYear :: forall a. { age :: Int | a } -> { age :: Int | a }
passYear x = x { age = x.age + 1 }

main :: Effect Unit
main = do
  let
    r = { age: 1 }
  log $ show r
  log $ show $ passYear r
  log $ show r

gets:

{ age: 1 }
{ age: 2 }
{ age: 2 }

expected:

{ age: 1 }
{ age: 2 }
{ age: 1 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    GolangApplies to the Go targetbug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions