codeconsole commented on PR #3091: URL: https://github.com/apache/groovy/pull/3091#issuecomment-6526846654
@daniellansun thanks. 1. The set lived as long as the visitor, and `StaticTypesTransformation` / `StaticCompileTransformation` create one visitor per annotated class or method, so it was bounded by that, not by the compilation unit. It is now tighter (2b334f3834): `visitClass`, `visitConstructorOrMethod` and `visitObjectInitializerStatements` each start a fresh set and restore the enclosing one when they finish, so a member's guards are dropped once the member is checked. It is a swap rather than a `clear()` because `inferReturnTypeOnDemand` checks another method from inside an expression, and anonymous inner classes can be visited inline; a clear there would drop the guards of the condition being visited. `testInstanceOf33` covers that case (`if (check1(x) && x instanceof String) x.length()` with `check1` inferred on demand); its `@CompileStatic` variant fails with a naive per-member clear. Closures are visited inline and share their member's set. 76e9cc928b also corrects the issue number in the test comments (GROOVY-12492 was the wrong one). 2. `visitExpressionStatement` behaves as on master: master already pushed a frame per expression statement and popped it, keeping only the assignment marker; I moved that body into `popTemporaryTypeInfoKeepingAssignments` so the loops can reuse it. `x instanceof String; x.length()` and `boolean b = x instanceof String; x.length()` fail to compile on both. The behaviour change is elsewhere: narrowing within an expression outside a guard position (`'' + (x instanceof String) + x.length()`, `foo(x instanceof String, x.length())`, list elements, `==` against another value, the right operand of `&`), the `== false` / `!= true` branch, and a use after a loop whose condition checked the variable. Those compiled before and are now compile errors; under `@CompileStatic` they threw `ClassCastException` whenever the check was false. Added a Groovy 7 entry to COMPATIBILITY.md (1b856c3b9b), a paragraph in the description, and the note on GROOVY-12562. 3. Out of scope and unchanged. `case String:` narrows through `visitCaseStatement`, which calls `pushInstanceOfTypeInfo` directly and never goes through the guard set, and a `catch` parameter has its declared type. `@CompileStatic` scripts compiled against master's visitor and the branch's give the same results for `case String:`, `case String ->`, use after a switch, single and multi-catch, and `instanceof` inside `try`/`catch`/`finally`. Also merged master. The `groovy.transform.stc` and `org.codehaus.groovy.classgen.asm.sc` packages pass (4,555 tests; one `@Grab` download failure that passes on rerun), as do the Checkstyle and CodeNarc gates. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
