[Vala] add check lifetime



Hi,

Sometime can happes to have code like:

string lifetime(string a) {
    {
        string b = "pippo";
        a = b;
    }
    stdout.printf (a + "\n");
    return a;
}

void main () {
    stdout.printf (lifetime("pippo") + "\n");
}

or

simplier:


void main () {

  unowned string a = "123";

  {

    string b = a;

  }

  stdout.printf (a);

}


both code are buggy because an unowned variable is used to contain
data with reduce lifetime.

Is it possible to add during:

- assigmend

- initialization

- parameter initialization (for async function)

a check over that? I think that the vala compiler known exactly the
lifetime ove each variable and so it can prevent (with error or
warning) to write this typo of bug.

I'm reading the vala source code:

valaassigment.vala

valalocalvariable.vala

and I think that near the check of "Assignment: Cannot convert from"
it is "easy" to add a check that

IF

    left is owned and rigth is disposable  AND

   left.scope is included in right.scope AND

   NOT right.scope is included in left.scope

THEN

there is a bug


is it possible to do that? is it possible (and how) to know the scope
of left and right operand?


many thanks

regards


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]