ShaderLang icon indicating copy to clipboard operation
ShaderLang copied to clipboard

[Sanitization] Return type isn't validated against function return type

Open SirLynix opened this issue 3 years ago • 0 comments

Currently, this code compiles correctly and shouldn't:

fn get_value() -> i32 {
    return 42.666; //< should trigger an error
}

Also

fn get_value() -> i32 {
    return; //< should trigger an error
}

A new type of error should be added to handle this.

A more difficult case to handle is this one:

fn get_value(v: bool) -> i32 {
    if (v)
        return 42;

    // should trigger an error: missing return
}

This last example requires a CFG (Control Flow Graph) to detect the error, I suggest to keep this case for another issue.

SirLynix avatar Jun 21 '22 10:06 SirLynix