winglang / winglang/wing

`json` can be mutated

Open
#7,002 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug 🛠️ compiler
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

I tried this:
let a: MutJson = {a: 1, b: 0};
let b = MutJson {a: 1, b: 0};
let c = {a: 1, b: 0};
let d: Json = {a: 1, b: 0};
let e = Json {a: 1, b: 0};

let testMutJson = (x: MutJson) => {
  x.delete("a");
  log(x); // logs { b: 0 } each time :/
};

testMutJson(a);
log(a);
testMutJson(b);
log(b);
testMutJson(c);
log(c);
testMutJson(d);
log(d);
testMutJson(e);
log(e);
This happened:
image
I expected this:

to throw an error for the immutable jsons

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.82.1

Node.js Version

No response

Platform(s)

MacOS

Community Notes
  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the MutJson and Json examples shown in the report, then trace how delete("a") is handled for each value. Done means immutable Json values reject mutation while MutJson values continue to allow it; add or update coverage for these examples and verify the behavior on macOS with Wing 0.82.1.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.