summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-10-26 23:25:03 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-11-05 10:39:20 +0000
commitf8a067866536e9017229b494f105edbc1eb1be20 (patch)
treec300e4bc6d160b9d0d9864bb29018dcf20bb3527
parent2e7cc32f51166ed739e4052f943368cbc3a142c4 (diff)
downloadswig-f8a067866536e9017229b494f105edbc1eb1be20.tar.gz
Improve R wrapper error message calling overloaded methods
when incorrect types passed are passed to the overloaded methods. Old unhelpful error message: Error in f(...) : could not find function "f" Example of new improved error message: Error in use_count(k) : cannot find overloaded function for use_count with argtypes (NULL)
-rw-r--r--CHANGES.current10
-rw-r--r--Examples/test-suite/r/li_boost_shared_ptr_runme.R2
-rw-r--r--Source/Modules/r.cxx12
3 files changed, 18 insertions, 6 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 0af67c484..693f8f3bf 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -11,3 +11,13 @@ Version 4.1.1 (in progress)
[R] #2386 Fix memory leak in R shared_ptr wrappers.
Fix leak when a cast up a class inheritance chain is required.
+2022-10-26: wsfulton
+ [R] Improve R wrapper error message when calling overloaded methods
+ when incorrect types passed are passed to the overloaded methods.
+
+ Old unhelpful error message:
+ Error in f(...) : could not find function "f"
+
+ Example of new improved error message:
+ Error in use_count(k) :
+ cannot find overloaded function for use_count with argtypes (NULL)
diff --git a/Examples/test-suite/r/li_boost_shared_ptr_runme.R b/Examples/test-suite/r/li_boost_shared_ptr_runme.R
index 1f7507337..ec8c66dcf 100644
--- a/Examples/test-suite/r/li_boost_shared_ptr_runme.R
+++ b/Examples/test-suite/r/li_boost_shared_ptr_runme.R
@@ -570,7 +570,7 @@ testSuite <- function() {
k = m$SmartMemberValue;
if (!is.null(k))
stop("expected null");
- #testSuite_verifyCount(0, k); # this does not work for nulls
+ testSuite_verifyCount(0, k); # this does not work for nulls
# plain by value
bNotCatched = F
diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
index e1fd422dd..e3d69329b 100644
--- a/Source/Modules/r.cxx
+++ b/Source/Modules/r.cxx
@@ -1566,7 +1566,8 @@ void R::dispatchFunction(Node *n) {
Printv(f->code,
"argtypes <- mapply(class, list(...));\n",
"argv <- list(...);\n",
- "argc <- length(argtypes);\n", NIL );
+ "argc <- length(argtypes);\n",
+ "f <- NULL;\n", NIL);
Printf(f->code, "# dispatch functions %d\n", nfunc);
int cur_args = -1;
@@ -1649,11 +1650,12 @@ void R::dispatchFunction(Node *n) {
}
}
if (cur_args != -1) {
- Printf(f->code, "} else {\n"
- "stop(\"cannot find overloaded function for %s with argtypes (\","
- "toString(argtypes),\")\");\n"
- "}", sfname);
+ Printf(f->code, "};\n");
}
+ Printf(f->code, "if (is.null(f)) {\n"
+ "stop(\"cannot find overloaded function for %s with argtypes (\","
+ "toString(argtypes),\")\");\n"
+ "}", sfname);
Printv(f->code, ";\nf(...)", NIL);
Printv(f->code, ";\n}", NIL);
Wrapper_print(f, sfile);