Skip to content

Commit 05862d0

Browse files
committed
AbstractMethodBuiltins __NAME__ handle CannotCastException
1 parent a3244e1 commit 05862d0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__SELF__;
3636
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
3737
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
38-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REDUCE__;
3938
import static com.oracle.graal.python.nodes.SpecialMethodNames.__HASH__;
39+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REDUCE__;
4040

4141
import java.util.List;
4242

@@ -235,14 +235,22 @@ public abstract static class NameNode extends PythonUnaryBuiltinNode {
235235
Object getName(VirtualFrame frame, PBuiltinMethod method,
236236
@Cached.Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
237237
@Cached.Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
238-
return toJavaStringNode.execute(pol.lookupAttribute(method.getFunction(), frame, __NAME__));
238+
try {
239+
return toJavaStringNode.execute(pol.lookupAttribute(method.getFunction(), frame, __NAME__));
240+
} catch (CannotCastException cce) {
241+
throw CompilerDirectives.shouldNotReachHere();
242+
}
239243
}
240244

241245
@Specialization
242246
Object getName(VirtualFrame frame, PMethod method,
243247
@Cached.Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
244248
@Cached.Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
245-
return toJavaStringNode.execute(pol.lookupAttribute(method.getFunction(), frame, __NAME__));
249+
try {
250+
return toJavaStringNode.execute(pol.lookupAttribute(method.getFunction(), frame, __NAME__));
251+
} catch (CannotCastException cce) {
252+
throw CompilerDirectives.shouldNotReachHere();
253+
}
246254
}
247255
}
248256

@@ -292,7 +300,7 @@ private Object getQualName(VirtualFrame frame, Object self, Object func, TypeNod
292300

293301
try {
294302
String typeQualName = toJavaStringNode.execute(pol.lookupAttributeStrict(type, frame, __QUALNAME__));
295-
return composeQualName(typeQualName, getName(frame, func, toJavaStringNode, pol));
303+
return PythonUtils.format("%s.%s", typeQualName, getName(frame, func, toJavaStringNode, pol));
296304
} catch (CannotCastException cce) {
297305
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.IS_NOT_A, __QUALNAME__, "unicode object");
298306
}
@@ -301,11 +309,6 @@ private Object getQualName(VirtualFrame frame, Object self, Object func, TypeNod
301309
private String getName(VirtualFrame frame, Object func, CastToJavaStringNode toJavaStringNode, PythonObjectLibrary pol) {
302310
return toJavaStringNode.execute(pol.lookupAttribute(func, frame, __NAME__));
303311
}
304-
305-
@CompilerDirectives.TruffleBoundary
306-
private static Object composeQualName(String typeQualName, String name) {
307-
return String.format("%s.%s", typeQualName, name);
308-
}
309312
}
310313

311314
@Builtin(name = __REDUCE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2)

0 commit comments

Comments
 (0)