Skip to content

Commit

Permalink
GROOVY-9510, GROOVY-10192
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 9, 2023
1 parent 3ac5083 commit e2c2144
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,20 @@ public void testDataTableChecks() {
assertType(source, offset, offset + 1, "java.lang.Object");
assertDeclaringType(source, offset, offset + 1, "SpockTests");
}

@Test
public void testRequiresCondition() {
//@formatter:off
String source =
"final class SpockTests extends spock.lang.Specification {\n" +
" @spock.lang.Requires({ owner })\n" + // owner is static
" void testSomething() {\n" +
" expect:\n" +
" true\n" +
" }\n" +
"}\n";
//@formatter:on

assertType(source, "owner", "java.lang.Class<SpockTests>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -658,17 +658,21 @@ private void visitFieldInternal(final FieldNode node) {
}

private void visitMethodInternal(final MethodNode node) {
scopes.add(new VariableScope(scopes.getLast(), node, node.isStatic()));
ASTNode enclosingDeclaration0 = enclosingDeclarationNode;
enclosingDeclarationNode = node;
try {
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
visitAnnotations(node); // annotations are in class scope
scopes.add(new VariableScope(scopes.getLast(), node, node.isStatic()));
try {
visitConstructorOrMethod(node, node instanceof ConstructorNode || node.getName().equals("<clinit>"));
} finally {
scopes.removeLast().bubbleUpdates();
}
} catch (VisitCompleted vc) {
if (vc.status == VisitStatus.STOP_VISIT) {
throw vc;
}
} finally {
scopes.removeLast().bubbleUpdates();
enclosingDeclarationNode = enclosingDeclaration0;
}
}
Expand Down Expand Up @@ -940,7 +944,7 @@ public void visitClosureExpression(final ClosureExpression node) {
scope.addVariable("owner", closureType, VariableScope.CLOSURE_CLASS_NODE);
scope.addVariable("getOwner", closureType, VariableScope.CLOSURE_CLASS_NODE);
} else {
ClassNode ownerType = scope.getThis();
ClassNode ownerType = parent.getThis();
// GRECLIPSE-1348: if someone is silly enough to have a variable named "owner"; don't override it
VariableScope.VariableInfo info = scope.lookupName("owner");
if (info == null || info.type == null || info.scopeNode instanceof ClosureExpression) {
Expand Down Expand Up @@ -1115,7 +1119,6 @@ public void visitConstructorOrMethod(final MethodNode node, final boolean isCons
}
}
if (handleParameters(node.getParameters())) {
visitAnnotations(node);
if (!isConstructor || !(node.getCode() instanceof BlockStatement)) {
visitClassCodeContainer(node.getCode());
} else {
Expand Down

0 comments on commit e2c2144

Please sign in to comment.