slint-ui / slint

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

VSCode language server panic in dynamic_item_tree.rs #5205

Closed mitchgrout closed 4 months ago

mitchgrout commented 4 months ago

VSCode extension for slint crashed while editing a .slint file. Extension version was v1.5.1, and the error output:

thread 'main' panicked at internal\interpreter\dynamic_item_tree.rs:1828:14: called Result::unwrap() on an Err value: () note: run with RUST_BACKTRACE=1 environment variable to display a backtrace [Info - 11:55:35 AM] Connection to server got closed. Server will restart. true The Slint Language Server crashed. This is a bug.

For ease of access, the referenced function was extern "C" fn item_geometry

Crash occurred while renaming a callback of this form:

callback foo;
callback bar <= foo;

I'll try to find a concise way to trigger it if possible.

ogoffart commented 4 months ago

Thanks a lot for the bug report. It would be nice to have a reproducible example to be able to investigate the issue further.

mitchgrout commented 4 months ago

So the problem is not exactly with the LSP per se, but the fact that this code is considered legal by the compiler:

component Test {
  callback unused;
  callback x <=> unused;
}

i.e. a redefinition of an existing property as a callback.

Invoking slint-compiler on this will emit C++ code, although I'm yet to check if it actually compiles.

Running slint-viewer on this code will cause a panic, and attempting to use the Show Preview feature in VSCode (which I assume uses slint-viewer under the hood) will also panic and restart. If you run this code on Slintpad, you will kill the session and will have to reload the page to get live view working again.

This issue only appears to be a problem if you define the callback as being bound to another valid callback, so the following is still a diagnostic:

component Test {
  callback x;
}
ogoffart commented 4 months ago

Thanks a lot for providing a testcase. Fix in https://github.com/slint-ui/slint/pull/5216