@@ -46,19 +46,17 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
4646 if (!isFunction (target ) || !isFunction (current ))
4747 error ("Arguments must be functions." );
4848
49- SEXP tar_form , cur_form , args ;
49+ SEXP tar_form , cur_form , args , func ;
5050 SEXPTYPE tar_type = TYPEOF (target ), cur_type = TYPEOF (current );
5151 struct ALIKEC_res res = ALIKEC_res_init ();
5252
5353 // Translate specials and builtins to formals, if possible
5454
5555 args = PROTECT (list2 (ALIKEC_SYM_args , R_NilValue ));
56- if (
57- tar_type == SPECIALSXP || tar_type == BUILTINSXP ||
58- cur_type == SPECIALSXP || cur_type == BUILTINSXP
59- ) {
60- SET_TYPEOF (args , LANGSXP );
61- }
56+ SET_TYPEOF (args , LANGSXP );
57+ func = PROTECT (list3 (ALIKEC_SYM_function , R_NilValue , R_NilValue ));
58+ SET_TYPEOF (func , LANGSXP );
59+
6260 if (tar_type == SPECIALSXP || tar_type == BUILTINSXP ) {
6361 SETCADR (args , target );
6462 target = PROTECT (eval (args , R_BaseEnv ));
@@ -69,6 +67,16 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
6967 current = PROTECT (eval (args , R_BaseEnv ));
7068 } else PROTECT (R_NilValue );
7169
70+ // As of ~r86700 R became stricter about what we could call FORMALS on, so we
71+ // need to make sure that we do get actual formals and not NULL.
72+
73+ if (TYPEOF (target ) != CLOSXP ) {
74+ target = PROTECT (eval (func , R_BaseEnv ));
75+ } else PROTECT (R_NilValue );
76+ if (TYPEOF (current ) != CLOSXP ) {
77+ current = PROTECT (eval (func , R_BaseEnv ));
78+ } else PROTECT (R_NilValue );
79+
7280 // Cycle through all formals
7381
7482 int dots = 0 , dots_last = 0 , dots_reset = 0 , tag_match = 1 , dots_cur = 0 ;
@@ -156,7 +164,7 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
156164 res .dat .strings .target [2 ] = arg_type ;
157165 }
158166 }
159- UNPROTECT (3 );
167+ UNPROTECT (6 );
160168 if (!res .success ) res .wrap = allocVector (VECSXP , 2 );
161169 return res ;
162170}
0 commit comments