Skip to content

Commit 49d6beb

Browse files
committed
[jvm] Make nqp::findmethod throw an exception if it can't find the method.
1 parent 069d9ea commit 49d6beb

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/IndyBootstrap.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,6 @@ public static void methcallResolve_noa(Lookup caller, MutableCallSite cs, String
508508
/* Try to resolve method to a coderef. */
509509
SixModelObject invocant = (SixModelObject)args[0];
510510
SixModelObject invokee = Ops.findmethod(invocant, name, tc);
511-
if (invokee == null)
512-
throw ExceptionHandling.dieInternal(tc,
513-
"Method '" + name + "' not found for invocant of class '" + Ops.typeName(invocant, tc) + "'");
514511
CodeRef cr;
515512
if (invokee instanceof CodeRef) {
516513
cr = (CodeRef)invokee;
@@ -573,9 +570,6 @@ public static void methcallCacheMono_noa(String name, CallSiteDescriptor csd,
573570
}
574571
else {
575572
SixModelObject invokee = Ops.findmethod(invocant, name, tc);
576-
if (invokee == null)
577-
throw ExceptionHandling.dieInternal(tc,
578-
"Method '" + name + "' not found for invocant of class '" + Ops.typeName(invocant, tc) + "'");
579573

580574
if (invokee instanceof CodeRef) {
581575
cr = (CodeRef)invokee;
@@ -640,9 +634,6 @@ public static void indmethcallInvoker_noa(MutableCallSite cs, int csIdx,
640634
/* Try to resolve method to a coderef. */
641635
SixModelObject invocant = (SixModelObject)args[0];
642636
SixModelObject invokee = Ops.findmethod(invocant, name, tc);
643-
if (invokee == null)
644-
throw ExceptionHandling.dieInternal(tc,
645-
"Method '" + name + "' not found for invocant of class '" + Ops.typeName(invocant, tc) + "'");
646637
CodeRef cr;
647638
if (invokee instanceof CodeRef) {
648639
cr = (CodeRef)invokee;

src/vm/jvm/runtime/org/perl6/nqp/runtime/NativeCallOps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public static Object toJNAType(ThreadContext tc, SixModelObject o, ArgType targe
497497
/* TODO: Handle encodings. */
498498
o = Ops.decont(o, tc);
499499
if (Ops.isconcrete(o, tc) == 0) return null;
500-
SixModelObject meth = Ops.findmethod(o, "cstr", tc);
500+
SixModelObject meth = Ops.findmethodNonFatal(o, "cstr", tc);
501501
if (meth != null) {
502502
Ops.invokeDirect(tc, meth, new CallSiteDescriptor(new byte[] { ARG_OBJ }, null), new Object[] { o });
503503
CStrInstance cstr = (CStrInstance) Ops.decont(Ops.result_o(tc.resultFrame()), tc);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ public static SixModelObject hlllist(ThreadContext tc) {
25092509
public static SixModelObject hllhash(ThreadContext tc) {
25102510
return tc.curFrame.codeRef.staticInfo.compUnit.hllConfig.hashType;
25112511
}
2512-
public static SixModelObject findmethod(ThreadContext tc, SixModelObject invocant, String name) {
2512+
public static SixModelObject findmethodInCache(ThreadContext tc, SixModelObject invocant, String name) {
25132513
if (invocant == null)
25142514
throw ExceptionHandling.dieInternal(tc, "Cannot call method '" + name + "' on a null object");
25152515
invocant = decont(invocant, tc);
@@ -2521,6 +2521,13 @@ public static SixModelObject findmethod(ThreadContext tc, SixModelObject invocan
25212521
return meth;
25222522
}
25232523
public static SixModelObject findmethod(SixModelObject invocant, String name, ThreadContext tc) {
2524+
SixModelObject method = findmethodNonFatal(invocant, name, tc);
2525+
if (method == null)
2526+
throw ExceptionHandling.dieInternal(tc,
2527+
"Method '" + name + "' not found for invocant of class '" + typeName(invocant, tc) + "'");
2528+
return method;
2529+
}
2530+
public static SixModelObject findmethodNonFatal(SixModelObject invocant, String name, ThreadContext tc) {
25242531
if (invocant == null)
25252532
throw ExceptionHandling.dieInternal(tc, "Cannot call method '" + name + "' on a null object");
25262533
invocant = decont(invocant, tc);
@@ -2546,12 +2553,12 @@ public static SixModelObject findmethod(SixModelObject invocant, String name, Th
25462553
public static String typeName(SixModelObject invocant, ThreadContext tc) {
25472554
invocant = decont(invocant, tc);
25482555
SixModelObject how = invocant.st.HOW;
2549-
SixModelObject nameMeth = findmethod(tc, how, "name");
2556+
SixModelObject nameMeth = findmethodInCache(tc, how, "name");
25502557
invokeDirect(tc, nameMeth, howObjCallSite, new Object[] { how, invocant });
25512558
return result_s(tc.curFrame);
25522559
}
25532560
public static long can(SixModelObject invocant, String name, ThreadContext tc) {
2554-
return findmethod(invocant, name, tc) == null ? 0 : 1;
2561+
return findmethodNonFatal(invocant, name, tc) == null ? 0 : 1;
25552562
}
25562563
public static long eqaddr(SixModelObject a, SixModelObject b) {
25572564
return a == b ? 1 : 0;
@@ -2656,7 +2663,7 @@ public static long istype_nodecont(SixModelObject obj, SixModelObject type, Thre
26562663
/* If we get here, need to call .^type_check on the value we're
26572664
* checking. */
26582665
if (cache == null || (typeCheckMode & STable.TYPE_CHECK_CACHE_THEN_METHOD) != 0) {
2659-
SixModelObject tcMeth = findmethod(obj.st.HOW, "type_check", tc);
2666+
SixModelObject tcMeth = findmethodNonFatal(obj.st.HOW, "type_check", tc);
26602667
if (tcMeth == null)
26612668
return 0;
26622669
/* TODO: Review why the following busts stuff. */
@@ -2675,7 +2682,7 @@ public static long istype_nodecont(SixModelObject obj, SixModelObject type, Thre
26752682

26762683
/* If the flag to call .accepts_type on the target value is set, do so. */
26772684
if ((typeCheckMode & STable.TYPE_CHECK_NEEDS_ACCEPTS) != 0) {
2678-
SixModelObject atMeth = findmethod(type.st.HOW, "accepts_type", tc);
2685+
SixModelObject atMeth = findmethodNonFatal(type.st.HOW, "accepts_type", tc);
26792686
if (atMeth == null)
26802687
throw ExceptionHandling.dieInternal(tc,
26812688
"Expected accepts_type method, but none found in meta-object");

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/CArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public SixModelObject allocate(ThreadContext tc, STable st) {
4141
private void fillREPRData(ThreadContext tc, STable st) {
4242
CArrayREPRData data = new CArrayREPRData();
4343

44-
SixModelObject meth = Ops.findmethod(st.WHAT, "of", tc);
44+
SixModelObject meth = Ops.findmethodNonFatal(st.WHAT, "of", tc);
4545
if (meth == null)
4646
ExceptionHandling.dieInternal(tc, "CArray representation expects an 'of' method, specifying the element type");
4747

0 commit comments

Comments
 (0)