r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
412 stars 57 forks source link

infinite recursion when inheriting from same class #282

Open tdhock opened 11 months ago

tdhock commented 11 months ago

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