Skip to content

False error: state sets declared two levels up the hierarchy are not kept across a call #505

Open

Description

@CatarinaGamboa

Problem. Typestate lookups only see the state sets of a class and its immediate supertypes. A class two levels below the one declaring the sets loses them across a call.

// Grand.java
import liquidjava.specification.*;

@StateSet({"closed", "opened"})
@StateSet({"unlocked", "locked"})
class Grand {
    @StateRefinement(to = "closed(this) && unlocked(this)")
    public Grand() {}
}
// Parent.java
class Parent extends Grand {}
// Child.java
import liquidjava.specification.*;

public class Child extends Parent {
    @StateRefinement(from = "closed(this) && unlocked(this)", to = "opened(this)")
    public void open() {}

    @StateRefinement(from = "unlocked(this)")
    public void needsUnlocked() {}

    public static void main(String[] args) {
        Child c = new Child();
        c.open();
        c.needsUnlocked(); // lock set should be kept by open()
    }
}
State Refinement Error: found opened(c) but expected unlocked(c)

open() does not mention the lock set, so it should keep unlocked(c).

Cause. AuxStateHandler.getGhostStatesFor collects the class, its superclass and its interfaces, but not their supertypes. It also indexes by simple class name, so two classes with the same simple name in different packages share one lookup.

Fix. Collect the sets over all supertypes, by qualified declaring type.

Found while designing #502.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions