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

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

Closed
axoking opened this issue Apr 28, 2024 · 1 comment · Fixed by #5151
Closed

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

axoking opened this issue Apr 28, 2024 · 1 comment · Fixed by #5151
Assignees
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) bug Something isn't working

Comments

@axoking
Copy link

axoking commented Apr 28, 2024

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:

  • Declare a new component, let it inherit from e.g. a Rectangle
  • Inside the declaration, define an animation for any visual property
  • Also inside the declaration, define an init method and let it change any property of the component
  • Declare a window, in which you place the your component using a for loop

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 ogoffart self-assigned this Apr 29, 2024
@ogoffart
Copy link
Member

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 #4322 )

@ogoffart ogoffart added bug Something isn't working a:compiler Slint compiler internal (not the codegen, not the parser) labels Apr 29, 2024
@ogoffart ogoffart changed the title Compiler crashes with "called Option::unwrap() on a None value" Compiler panic compiling init callback from a component inlined into a repeater Apr 29, 2024
ogoffart added a commit that referenced this issue Apr 29, 2024
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
ogoffart added a commit that referenced this issue Apr 29, 2024
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
ogoffart added a commit that referenced this issue Apr 29, 2024
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants