slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 601 forks source link

Compiler panic compiling `init` callback from a component inlined into a repeater #5146

Closed axoking closed 6 months ago

axoking commented 6 months ago

I randomly found a bug in the compiler that panics with the following message:

i-slint-compiler-1.5.1/llr/lower_expression.rs:35:34:
  called `Option::unwrap()` on a `None` value

It appears under some weird circumstances. I was able to reproduce it like this:

For example:

component MyComponent inherits Rectangle {
  animate background {}
  init => {
    self.background = #000;
  }
}

export component MyWindow inherits Window {
  for _ in [1, 2, 3]: MyComponent {}
}

That bug also appears in SlintPad, it freezes the preview window and prints a similar error message in the JS console.

ogoffart commented 6 months ago

Thanks for the bug report. I can reproduce the issue. The problem is that the init callback is inlined in the wrong item tree. Most likely caused by https://github.com/slint-ui/slint/pull/4322 )