Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited methods in clone of non-portable object have incorrect environment #214

Closed
wch opened this issue Oct 19, 2020 · 0 comments · Fixed by #215
Closed

Inherited methods in clone of non-portable object have incorrect environment #214

wch opened this issue Oct 19, 2020 · 0 comments · Fixed by #215

Comments

@wch
Copy link
Member

wch commented Oct 19, 2020

When a non-portable object with inheritance is cloned, methods that are inherited (and not overridden) do not get the new object's environment. Originally from #212.

library(R6)
A <- R6Class("A",
  portable = F,
  public = list(
    getx = function() x,
    getx2 = function() x,
    x = 1
  )
)

B <- R6Class("B",
  portable = F,
  inherit = A,  
  public = list(
    # Override getx2, but not getx
    getx2 = function() x
  )
)

b <- B$new()
bc <- b$clone()
b$x <- 10

# Both of these return 10, which is correct
b$getx()
#> [1] 10
b$getx2()
#> [1] 10

# Returns 10, which is incorrect!
bc$getx()
#> [1] 10
# Returns 1, which is correct
bc$getx2()
#> [1] 1
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 a pull request may close this issue.

1 participant