Skip to content

Crash: @Ghost on a nested class gives "Sort mismatch ... supplied sort is Outer$Bag" #467

Open

Description

@CatarinaGamboa

Impact: any @Ghost declared on a nested class crashes verification of every refinement that uses it; the same class at top level verifies.

Minimal reproducer

import liquidjava.specification.Ghost;
import liquidjava.specification.Refinement;
import liquidjava.specification.StateRefinement;

public class Outer {
    @Ghost("int size")
    static class Bag {
        @StateRefinement(to = "size(this) == 0")
        public Bag() {}

        @StateRefinement(to = "size(this) == size(old(this)) + 1")
        public void add() {}

        @StateRefinement(from = "size(this) > 0")
        public void remove() {}
    }

    static void ok() {
        Bag b = new Bag();
        b.add();
        b.remove();
    }
}

Expected: Correct! Passed Verification., as for the same Bag as a top-level class.

Actual (main @ 0053074):

Error: Sort mismatch at argument #1 for function (declare-fun Outer$Bag.size (Outer.Bag) Int) supplied sort is Outer$Bag
 9 |         public Bag() {}
10 | 
11 |         @StateRefinement(to = "size(this) == size(old(this)) + 1")
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12 |         public void add() {}
13 | 

Error: Sort mismatch at argument #1 for function (declare-fun Outer$Bag.size (Outer.Bag) Int) supplied sort is Outer$Bag
12 |         public void add() {}
13 | 
14 |         @StateRefinement(from = "size(this) > 0")
   |                                  ^^^^^^^^^^^^^^
15 |         public void remove() {}
16 |     }

Cause. The two sides name the class's Z3 sort differently. TranslatorContextToZ3.addGhostFunction builds the ghost's domain from CtTypeReference.toString() (Outer.Bag), while TranslatorContextToZ3.getExpr builds the sort of this from getQualifiedName() (Outer$Bag). For a top-level class both are the same string. Using one naming for both (e.g. getQualifiedName() in addGhostFunction and getSort) should fix it.

🤖 Generated with Claude Code

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