Leave AssertThrowsOnLastStatement arguments inline when their type can't be rendered#1066
Merged
Merged
Conversation
…n't be rendered Anonymous and local class types (proper JavaType.Class, not JavaType.Unknown) render an invalid declared type such as `MyTest.1 x = ...`, which makes the extraction template generate the wrong number of statements and crashes the run. The #1059 guard only covered Unknown/None/Void/Null. Guard the template apply so any such failure leaves the argument inline instead of failing the recipe.
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.
What's changed?
AssertThrowsOnLastStatementintermittently crashed with:Root cause
#{} #{} = #{any()};. For an anonymous or local class the type is a fully-attributedJavaType.Class(notJavaType.Unknown), so the Fix AssertThrowsOnLastStatement crash on unattributed argument types #1059 guard (Unknown/None/Void/Null) doesn't catch it.getClassName()then produces invalid Java such as:MyTest.1doesn't parse as a type, so the stub yields the wrong statement count and the run fails. This only surfaced in real multi-module sources, which is why it was hard to isolate.Fix
Guard the template apply so any failure leaves the argument inline instead of failing the whole recipe run — a conservative fallback that also covers other un-renderable-type variants. The recipe still moves the earlier lambda statements out; only the un-renderable argument stays inline.
Checklist
Regression test (
argumentWithAnonymousClassTypeIsLeftInline) added and passingFull
AssertThrowsOnLastStatementTestpasseslicenseFormatcleanFixes moderneinc/customer-requests#2861