Skip to content

Commit fa18c45

Browse files
committed
[hotfix] fix __truffle_source__ builtin for generator functions
PullRequest: graalpython/402
2 parents c90a23b + 54a470d commit fa18c45

File tree

1 file changed

+7
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function

1 file changed

+7
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -33,6 +33,7 @@
3333
import com.oracle.graal.python.builtins.objects.object.PythonObject;
3434
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
3535
import com.oracle.graal.python.nodes.SpecialMethodNames;
36+
import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
3637
import com.oracle.truffle.api.CompilerAsserts;
3738
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3839
import com.oracle.truffle.api.RootCallTarget;
@@ -144,7 +145,11 @@ public void setDefaults(Object[] defaults) {
144145

145146
@TruffleBoundary
146147
public String getSourceCode() {
147-
SourceSection sourceSection = callTarget.getRootNode().getSourceSection();
148+
RootNode rootNode = callTarget.getRootNode();
149+
if (rootNode instanceof GeneratorFunctionRootNode) {
150+
rootNode = ((GeneratorFunctionRootNode) rootNode).getFunctionRootNode();
151+
}
152+
SourceSection sourceSection = rootNode.getSourceSection();
148153
if (sourceSection != null) {
149154
return sourceSection.getCharacters().toString();
150155
}

0 commit comments

Comments
 (0)