Bug 16973

Summary: callNextMethod() not finding the correct "next method"
Product: R Reporter: Hervé Pagès <hpages>
Component: S4methodsAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: normal CC: michafla
Priority: P5    
Version: R-devel (trunk)   
Hardware: All   
OS: All   

Description Hervé Pagès 2016-06-28 19:19:14 UTC
Here is how to reproduce:

  setClass("A", slots=c(stuff="ANY"))
  setClass("B", contains="A")
  setClass("C", contains="B")
  a <- new("A")
  b <- new("B")
  c <- new("C")

  setGeneric("foo", function(x) standardGeneric("foo"))
  setMethod("foo", "A", function(x) "A")
  setMethod("foo", "C", function(x) c(callNextMethod(x), "C"))

  foo(a) # A
  foo(b) # A
  foo(c) # A C

  setMethod("foo", "B", function(x) c(callNextMethod(x), "B"))

  foo(a) # A
  foo(b) # A B
  foo(c) # A C <--- wrong!

Looks like some caching is getting in the way.

Problem goes away when defining the foo#C method again:

  setMethod("foo", "C", function(x) c(callNextMethod(x), "C"))

  foo(a) # A
  foo(b) # A B
  foo(c) # A B C <--- ok

Thanks,
H.
Comment 1 Michael Lawrence 2016-06-29 12:53:26 UTC
Thanks, I've fixed this. Just need to test and commit.