Skip to content

count special module methods once per name for completion - #1530

Open
kevinushey wants to merge 1 commit into
masterfrom
bugfix/module-complete-specials
Open

kevinushey wants to merge 1 commit into
masterfrom
bugfix/module-complete-specials

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Fixes #1529.

class_<T>::complete() (behind tab completion on module objects) sizes its output as the number of method names minus specials, but AddMethod() incremented specials once per overload of a [-prefixed method. With [[ overloaded, the last ordinary method went missing from the completions. If the class had no ordinary methods, the subtraction underflowed and the loop ran past the end of the method map. See #1529 for the reprex.

Change (inst/include/Rcpp/module/class.h, class_::AddMethod): increment specials only when a new method name is inserted, so it counts names, which is what complete() assumes. This also keeps the count right for methods copied in by derives(), which go through AddMethod() as well.

Tests (inst/tinytest/test_module.R, classes added to cpp/Module.cpp):

  • ModuleBrackets overloads [[ and has an ordinary method and a field: completion gives c("total( ", "value"), and [[ still dispatches.
  • ModuleBracketsOnly overloads [[ and has only a field: completion gives "value".

Verification:

  • The reprex from tab completion on module objects drops methods or reads past the method map when [[ is overloaded #1529 prints "scale" and attempt to set index 0/0 in SET_STRING_ELT against current master, and "total( " "scale" and "scale" against this branch.
  • Against master the new tests fail: test_module.R stops with the same SET_STRING_ELT error. On this branch test_module.R (48/48), test_modref.R, test_expose_class.R and test_module_client_package.R pass with RunAllRcppTests=yes RunVerboseRcppTests=yes (R 4.6.1, macOS).

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests (module test files run locally as above)
  • Preferably, new tests were added which fail without the change
  • Document the changes by file in ChangeLog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tab completion on module objects drops methods or reads past the method map when [[ is overloaded

1 participant