PistonDevelopers / dyon

A rusty dynamically typed scripting language
Apache License 2.0
1.77k stars 55 forks source link

Bug in lifetime checker #715

Closed bvssvni closed 1 year ago

bvssvni commented 2 years ago
fn main() {
    x := 0
    a := []
    y := 1
    foo(mut a, x, y)
}

fn foo(mut a, x: 'a, y) {
    a = [x, y]
}
bvssvni commented 1 year ago

This can be solved by introducing LifetimeError and LifetimeResult:

#[derive(Debug)]
pub enum LifetimeError {
    None,
    FailedToUnify,
}

pub type LifetimeResult = Result<Lifetime, LifetimeError>;

The LifetimeError::FailedToUnify is used when it is undecidable which lifetime to assign to the expression.

In most cases, one can solve these problems using clone, so this is suggested in the error message.

This design makes a pragmatic tradeoff between practical use and computational complexity.