Skip to content

Conversation

@rcosta358
Copy link
Collaborator

@rcosta358 rcosta358 commented Oct 23, 2025

Fixed issue where this references in parameter refinements were not resolved, because they weren’t being substituted with the specific object on which the method was invoked.

Now we can actually catch index out-of-bounds errors! 😄

@ExternalRefinementsFor("java.util.ArrayList")
@Ghost("int size")
public interface ArrayListRefinements<E> {

    public void ArrayList();

	@StateRefinement(to = "size(this) == size(old(this)) + 1")
	public boolean add(E elem);

	// this refinement previously caused the error "Variable 'this' not found"
	public E get(@Refinement("_ < size(this)") int index); 
}

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.get(0); // refinement error!
    }
}

@rcosta358 rcosta358 self-assigned this Oct 23, 2025
@rcosta358 rcosta358 added the enhancement New feature or request label Oct 23, 2025
@rcosta358 rcosta358 requested a review from alcides October 23, 2025 14:45
@rcosta358 rcosta358 changed the title Substitute this in Parameter Refinements Fix this Resolution in Parameter Refinements Oct 23, 2025
@rcosta358 rcosta358 added bug Something isn't working and removed enhancement New feature or request labels Oct 24, 2025
Copy link
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@rcosta358 rcosta358 merged commit 72c1ea6 into liquid-java:main Oct 29, 2025
1 check passed
@rcosta358 rcosta358 deleted the fix-this-in-parameters branch October 29, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Referencing ghost variable names within function parameter refinements should be allowed

2 participants