Skip to content

Commit 254706b

Browse files
committed
count special module methods once per name for completion
1 parent a6f354e commit 254706b

4 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎ChangeLog‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2026-10-29 Kevin Ushey <kevinushey@gmail.com>
2+
3+
* inst/include/Rcpp/module/class.h (class_::AddMethod): Count special
4+
'[' methods once per name rather than once per overload, as complete()
5+
expects; overloading '[[' dropped methods from completion or ran past
6+
the end of the method map (#1529)
7+
* inst/tinytest/cpp/Module.cpp: Add classes overloading '[['
8+
* inst/tinytest/test_module.R: Test their completions
9+
110
2026-10-23 Dirk Eddelbuettel <edd@debian.org>
211

312
* DESCRIPTION (Version, Date): Roll micro version and date

‎inst/include/Rcpp/module/class.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@
250250
typename map_vec_signed_method::iterator it = ptr->vec_methods.find( name_ ) ;
251251
if( it == ptr->vec_methods.end() ){
252252
it = ptr->vec_methods.insert( vec_signed_method_pair( name_, new vec_signed_method() ) ).first ;
253+
// complete() relies on this counting names, not overloads
254+
if( *name_ == '[' ) ptr->specials++ ;
253255
}
254256
(it->second)->push_back( new signed_method_class(m, valid, docstring ) ) ;
255-
if( *name_ == '[' ) ptr->specials++ ;
256257
return *this ;
257258
}
258259

‎inst/tinytest/cpp/Module.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,27 @@ double Test_get_x_pointer(ModuleTest* x) {
137137
return x->value;
138138
}
139139

140+
class ModuleBrackets {
141+
public:
142+
ModuleBrackets() : value(1.0) {}
143+
144+
double at(int i) { return value * i; }
145+
double at2(int i, int j) { return value * i * j; }
146+
double total() { return value; }
147+
148+
double value;
149+
};
150+
151+
class ModuleBracketsOnly {
152+
public:
153+
ModuleBracketsOnly() : value(1.0) {}
154+
155+
double at(int i) { return value * i; }
156+
double at2(int i, int j) { return value * i * j; }
157+
158+
double value;
159+
};
160+
140161
class ModuleGadget {
141162
public:
142163
ModuleGadget() {}
@@ -217,6 +238,22 @@ RCPP_MODULE(demoModule) {
217238
.method("get" , &ModuleRandomizer::get)
218239
;
219240

241+
// overloaded [[, with and without an ordinary method
242+
class_<ModuleBrackets>("ModuleBrackets")
243+
.constructor()
244+
.method("[[", &ModuleBrackets::at)
245+
.method("[[", &ModuleBrackets::at2)
246+
.method("total", &ModuleBrackets::total)
247+
.field("value", &ModuleBrackets::value)
248+
;
249+
250+
class_<ModuleBracketsOnly>("ModuleBracketsOnly")
251+
.constructor()
252+
.method("[[", &ModuleBracketsOnly::at)
253+
.method("[[", &ModuleBracketsOnly::at2)
254+
.field("value", &ModuleBracketsOnly::value)
255+
;
256+
220257
class_<ModuleGadget>("ModuleGadget")
221258
.constructor()
222259
.method("value", static_cast<void (ModuleGadget::*)(int)>(&ModuleGadget::value))

‎inst/tinytest/test_module.R‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ expect_equal(r$get(10), x10)
108108
r <- new( ModuleRandomizer )
109109
expect_error( r$get(10L), "not initialized" )
110110

111+
## completion lists the ordinary methods and the fields; an overloaded [[
112+
## used to be counted once per overload, which dropped the last ordinary
113+
## method, or ran past the end of the method map when there was none (#1529)
114+
brackets <- new( ModuleBrackets )
115+
expect_equal( Rcpp:::complete( brackets ), c("total( ", "value") )
116+
expect_equal( brackets[[2L]], 2.0 )
117+
expect_equal( Rcpp:::complete( new( ModuleBracketsOnly ) ), "value" )
118+
111119
# test.Module.flexible.semantics <- function( ){
112120
expect_equal( test_reference( seq(0,10) ), 11L )
113121
expect_equal( test_const_reference( seq(0,10) ), 11L )

0 commit comments

Comments
 (0)