R6 icon indicating copy to clipboard operation
R6 copied to clipboard

infinite recursion when inheriting from same class

Open tdhock opened this issue 6 months ago • 0 comments

hi, I made a mistake, accidentally specifying the class itself as inherit, which resulted in an infinite loop. I was surprised to see that is actually even allowed for the class definition:

> MyClass=R6::R6Class(inherit=MyClass)

I actually got no output (success) from the above line of code. I would have expected/liked an error when running the above code, something like below:

> R6::R6Class(inherit=Undefined)$new()
Error in eval(inherit, parent_env, NULL) : object 'Undefined' not found

However I only got an error message later, shown below

> MyClass=R6::R6Class(inherit=MyClass)
> MyClass$new()
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

It was easy how to fix this issue, but it would have been even more obvious/user friendly if the error happens earlier (on R6Class definition), would that be possible please? Thanks

tdhock avatar Dec 12 '23 16:12 tdhock