Skip to content

Commit c681fd6

Browse files
committed
fix parser tests for module roots trying to return a value
1 parent a6ef2b2 commit c681fd6

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@
7979
import com.oracle.graal.python.nodes.expression.UnaryArithmetic;
8080
import com.oracle.graal.python.nodes.frame.DeleteGlobalNode;
8181
import com.oracle.graal.python.nodes.frame.DestructuringAssignmentNode;
82+
import com.oracle.graal.python.nodes.frame.FrameSlotIDs;
8283
import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode;
8384
import com.oracle.graal.python.nodes.frame.WriteGlobalNode;
85+
import com.oracle.graal.python.nodes.frame.WriteLocalVariableNode;
8486
import com.oracle.graal.python.nodes.frame.WriteNode;
8587
import com.oracle.graal.python.nodes.function.FunctionDefinitionNode;
8688
import com.oracle.graal.python.nodes.function.GeneratorExpressionNode;
@@ -135,18 +137,32 @@ <T> T getChild(Node result, int num, Class<? extends T> klass) {
135137
if (++i <= num) {
136138
continue;
137139
}
138-
if (n instanceof ExpressionNode.ExpressionStatementNode) {
139-
n = n.getChildren().iterator().next();
140-
} else if (n instanceof ExpressionNode.ExpressionWithSideEffects) {
141-
n = n.getChildren().iterator().next();
142-
}
140+
n = unpackModuleBodyWrappers(n);
143141
assertTrue("Expected an instance of " + klass + ", got " + n.getClass(), klass.isInstance(n));
144142
return klass.cast(n);
145143
}
146144
assertFalse("Expected an instance of " + klass + ", got null", true);
147145
return null;
148146
}
149147

148+
private Node unpackModuleBodyWrappers(Node n) {
149+
Node actual = n;
150+
if (n instanceof ExpressionNode.ExpressionStatementNode) {
151+
actual = n.getChildren().iterator().next();
152+
} else if (n instanceof ExpressionNode.ExpressionWithSideEffects) {
153+
actual = n.getChildren().iterator().next();
154+
} else if (n instanceof WriteLocalVariableNode) {
155+
if (((WriteLocalVariableNode) n).getIdentifier().equals(FrameSlotIDs.RETURN_SLOT_ID)) {
156+
actual = ((WriteLocalVariableNode) n).getRhs();
157+
}
158+
}
159+
if (actual == n) {
160+
return n;
161+
} else {
162+
return unpackModuleBodyWrappers(actual);
163+
}
164+
}
165+
150166
<T> T getFirstChild(Node result, Class<? extends T> klass) {
151167
return getChild(result, 0, klass);
152168
}

0 commit comments

Comments
 (0)