encore icon indicating copy to clipboard operation
encore copied to clipboard

Variable accessible after being consumed

Open supercooldave opened this issue 8 years ago • 1 comments

In feature/capabilities branch, one can consume a variable and then, for example, call a method on it. When the variable is consumed it is set to null. That this occurs is statically known, so perhaps the programmer should be warned.

In terms of capabilities, consume consumes a capability, so its loss should/could be tracked statically.

The following program illustrates the bug.

trait Box

trait Lid
  require numberOfSeals : int

  def seals() : int
    this.numberOfSeals

passive class Chest : read Box + thread Lid
  numberOfSeals : int

class Main
  def main() : void {
    let c = new Chest;
    let d : read Box, e : thread Lid = consume c;
    print c.seals() -- c is statically known to be null here. 
  }

This program results in a Segmentation fault:

dhcp-11-160:kappa dave$ ./consume
Segmentation fault: 11

supercooldave avatar May 26 '16 11:05 supercooldave

Static tracking of consumes is an important step in the quest for getting rid of null!

EliasC avatar May 26 '16 12:05 EliasC