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

Assign to a non-derived private field breaks when a public derived field exists with the same name #15273

Closed
jkbz64 opened this issue Feb 11, 2025 · 4 comments · Fixed by #15276
Assignees

Comments

@jkbz64
Copy link

jkbz64 commented Feb 11, 2025

Describe the bug

Declaring and assigning to a non-derived private field in a class that has a public derived field with the same name breaks with a Cannot assign to derived state compile error, this seems to be broken by #15228.

<script>
  class X {
    #deps = () => [];
  
    deps = $derived.by(() => {
      return [];
    });		
  		
    constructor(f = () => []) {
      this.#deps = f;
    }
  }
</script>

This was working/compiling correctly in 5.19.9

Reproduction

https://svelte.dev/playground/hello-world?version=5.19.10#H4sIAAAAAAAAA22Oy4rDMAxFf0WoXSQQMvv0Ad3NJwzUWaS2Qg2ubCyl0xDy70MmDcxiNloczr1XE3L3IGzwk0KI8B1zcFCQ80quxAp7H0iwuU6oY1q8BWC1pS4p1fKkoAu7dUL_cRtZiVWwwaPY7JOeDRu2oROBL5gMA-wcJYETFCWcznBtD4sB8KZ7R9k_ydW3sViN3xBAJh0yrz7AXB6MGjW8XgAbWTQPVmMu-j_t5ZbXu5d62-7XEsOz4ePH-1OsUOml2GgeaG7nH6W6CcAxAQAA

Logs

Cannot assign to derived state
https://svelte.dev/e/constant_assignment

System Info

System:
    OS: Linux 6.12 Fedora Linux Asahi Remix 41 (Forty One)
    CPU: (8) arm64 unknown
    Memory: 15.83 GB / 31.12 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.20.4 - ~/.n/bin/node
    Yarn: 1.22.21 - ~/.n/bin/yarn
    npm: 10.7.0 - ~/.n/bin/npm
    pnpm: 10.2.1 - ~/.local/share/pnpm/pnpm
    bun: 1.2.2 - ~/.n/bin/bun

Severity

annoyance

@jkbz64 jkbz64 changed the title Assign to a non-derived private breaks when a public derived field exists with the same name Assign to a non-derived private field breaks when a public derived field exists with the same name Feb 11, 2025
@Prinzhorn
Copy link
Contributor

@paoloricciuti #15228

@paoloricciuti
Copy link
Member

Ugh...will fix this asap

@paoloricciuti paoloricciuti self-assigned this Feb 12, 2025
@singlyfy
Copy link

I am a bit confused with the fix..or at least with its description:

"fix: allow mutation of private derived state" I guess it disabled re-assigning, which broke following library:

Refzlund/runic-reorder#4

@paoloricciuti
Copy link
Member

I am a bit confused with the fix..or at least with its description:

"fix: allow mutation of private derived state" I guess it disabled re-assigning, which broke following library:

Refzlund/runic-reorder#4

Yeah while working on that I noticed there was no check to prevent reassignment of public deriverà and added that too. The fix would be quite straightforward tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants