Skip to content

Commit ffb3f61

Browse files
committed
raise when trying to convert a built-in string to index
1 parent e44b1a1 commit ffb3f61

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonStringExports.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242

4343
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4444
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
45+
import com.oracle.graal.python.nodes.PRaiseNode;
4546
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
47+
import com.oracle.truffle.api.dsl.Cached;
4648
import com.oracle.truffle.api.library.ExportLibrary;
4749
import com.oracle.truffle.api.library.ExportMessage;
4850

@@ -84,4 +86,10 @@ static byte[] getBufferBytes(String str) {
8486
static long hash(String self) {
8587
return self.hashCode();
8688
}
89+
90+
@ExportMessage
91+
static int asIndex(String self,
92+
@Cached PRaiseNode raise) {
93+
throw raise.raise(PythonBuiltinClassType.TypeError, "'%p' object cannot be interpreted as an integer", self);
94+
}
8795
}

0 commit comments

Comments
 (0)