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.31k stars 583 forks source link

Multiple component exported with different names causes panic in `generate_item_indices.rs` #6559

Open qarmin opened 1 week ago

qarmin commented 1 week ago

File content(at the bottom should be attached raw, not formatted file - github removes some non-printable characters, so copying from here may not work):

Foo:=Rectangle{}export{Foo}export{Foo as g}

Source code of program that trying to compile code - https://github.com/qarmin/Automated-Fuzzer/blob/master/src/crates/slint/src/main.rs

command

cargo install --git https://github.com/qarmin/Automated-Fuzzer/ slint
RUST_BACKTRACE=1 timeout -v 100 slint TEST___FILE.slint

cause this

thread 'main' panicked at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/passes/generate_item_indices.rs:90:67:
called `Result::unwrap()` on an `Err` value: 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/27861c429af736ea3a6bb015956c7286071b286d/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/27861c429af736ea3a6bb015956c7286071b286d/library/core/src/panicking.rs:74:14
   2: core::result::unwrap_failed
             at /rustc/27861c429af736ea3a6bb015956c7286071b286d/library/core/src/result.rs:1700:5
   3: core::result::Result<T,E>::unwrap
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1104:23
   4: <i_slint_compiler::passes::generate_item_indices::Helper as i_slint_compiler::generator::ItemTreeBuilder>::push_native_item
   5: i_slint_compiler::generator::build_item_tree::visit_item
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/generator.rs:384:13
   6: i_slint_compiler::generator::build_item_tree
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/generator.rs:168:9
   7: i_slint_compiler::passes::generate_item_indices::generate_item_indices
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/passes/generate_item_indices.rs:40:5
   8: i_slint_compiler::passes::run_passes::{{closure}}::{{closure}}
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/passes.rs:224:13
   9: i_slint_compiler::object_tree::Document::visit_all_used_components
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/object_tree.rs:263:13
  10: i_slint_compiler::passes::run_passes::{{closure}}
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/passes.rs:222:5
  11: i_slint_compiler::compile_syntax_node::{{closure}}
             at /home/runner/.cargo/git/checkouts/slint-8153123e5dffa129/c2ebe3c/internal/compiler/lib.rs:299:76
  12: spin_on::spin_on
             at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spin_on-0.1.1/src/lib.rs:78:38
  13: slint::check_file
             at ./src/crates/slint/src/main.rs:45:21
  14: slint::main
             at ./src/crates/slint/src/main.rs:25:9
  15: core::ops::function::FnOnce::call_once
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

##### Automatic Fuzzer note, output status "None", output signal "Some(6)"

compressed.zip

ogoffart commented 4 days ago

Seems like an issue if we have the same component exported with different names.

Another testcase would be:

component Foo {
 // ...
}
export { Foo as Bob }
export { Foo as Bar }

We process these elements several times which is a bit wasteful. And harmful for the generate_item_indices pass as it panics. The panic could be fairly easily solved, but that would still generate the component multiple times instead of giving them aliases.