Repository navigation
Check typestate calls made directly on a constructor call - #361
Open
CatarinaGamboa wants to merge 1 commit into
Open
CatarinaGamboa wants to merge 1 commit into
CatarinaGamboa wants to merge 1 commit into
Conversation
Fixes #336. In `new T(args).method()` the receiver had no variable instance, so the method's from-state was never checked. The constructor call now gets a fresh instance in the state the constructor gives (with its supertypes), and the call is checked and transitions it like any other receiver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #336.
Problem
new Token(1).use()passed althoughToken(int)leaves the object inusedanduse()requiresfresh; the same call through a local was reported.prepareInvocationTargetonly knew variable reads and targets that already had an instance, so a constructor-call receiver had none andcheckTargetChangesskipped it. Real code does this often (new ServerSocket(port).accept(),new IOException(msg).initCause(e)).Change
AuxStateHandler.prepareInvocationTarget: when the target is a constructor call carrying its state (the constructor's to-state, or the class's default state, asgetConstructorInvocationRefinementsalready records), it creates a fresh variable instance in that state, records the type's supertypes on it (so a spec on a supertype applies), and makes it the invocation's target. The usual from-state check and transition then apply.Tests
ErrorConstructorReceiver:new ErrorReceiverToken(1).use()givesfound used(#fresh) but expected fresh(#fresh); passed on main.CorrectConstructorReceiver:new …().use()andnew …(1).report()pass.mvn testpasses.🤖 Generated with Claude Code