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.07k stars 573 forks source link

Panic in slint compiler: The remove return pass should have removed all return #5430

Closed npwoods closed 3 months ago

npwoods commented 3 months ago

Steps to reproduce:

  1. Open up attached minimal Rust project
  2. cargo build
    thread 'main' panicked at C:\<<redacted>>\.cargo\registry\src\index.crates.io-6f17d22bba15001f\i-slint-compiler-.6.0\llr\lower_expression.rs:199:13:
    The remove return pass should have removed all return

    bug-demo.zip

ogoffart commented 3 months ago

Thanks for the bug report. I can reproduce it.

It needs two files to be reproduced:

treeview.slint:

export global MyFluentPalette {
    property <bool> dark-color-scheme: {
        return false;
    }
    out property <brush> control-foreground: dark-color-scheme ? #FFFFFF : #000000E6;
}

main.slint

import { MyFluentPalette } from "treeview.slint";
export component AppWindow inherits Window {
    out property <bool> foo: MyFluentPalette.dark-color-scheme ? true : false;
}

Looks like property of global exported in another file are not properly handled

ogoffart commented 3 months ago

This happens for global on other files because then the property can be inlined, but it can also be reproduced by one file with a private property

export component AppWindow inherits Window {
    property <bool> xxx: {
        return false;
    }
    out property <string> foo: xxx ? "true" : "false";
}

The problem is that the condition contains a return: foo: if ({ return false; }) { "true" } else { "false" } Not only the returned is not removed, but it is wrong to inline returns

The remove return pass needs to be done before const propagation