File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 47
47
import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
48
48
import com .oracle .graal .python .nodes .IndirectCallNode ;
49
49
import com .oracle .graal .python .nodes .PRaiseNode ;
50
+ import com .oracle .graal .python .nodes .util .CastToJavaLongNode ;
50
51
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
51
52
import com .oracle .graal .python .runtime .PythonContext ;
52
53
import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
@@ -262,8 +263,16 @@ public Object asIndex(Object receiver) {
262
263
*/
263
264
public int asSizeWithState (Object receiver , LazyPythonClass errorType , ThreadState threadState ) {
264
265
if (threadState == null ) {
265
- asIndexWithState (receiver , threadState );
266
- assert false : "should not reach here" ;
266
+ // this will very likely always raise an integer interpretation error in asIndexWithState
267
+ long result = CastToJavaLongNode .getUncached ().execute (asIndexWithState (receiver , null ));
268
+ int intResult = (int ) result ;
269
+ if (intResult == result ) {
270
+ return intResult ;
271
+ } else if (errorType == null ) {
272
+ return result < 0 ? Integer .MIN_VALUE : Integer .MAX_VALUE ;
273
+ } else {
274
+ throw PRaiseNode .getUncached ().raiseNumberTooLarge (errorType , result );
275
+ }
267
276
}
268
277
return asSize (receiver , errorType );
269
278
}
You can’t perform that action at this time.
0 commit comments