Skip to content

Conversation

@arepnikov
Copy link

@arepnikov arepnikov commented Dec 28, 2023

Resolves #3 (If virtual or pure_virtual is declared in a class that already has a concrete implementation, raise an error)

Current Behavior

It is possible to inadvertently overwrite a concrete implementation with a virtual method:

class Example
  include SomeModule
  include SomeOtherModule
  
  module SomeModule
    def some_method
      ...
    end
  end

  module SomeOtherModule
    def self.included(cls)
      cls.class_exec do
         include Virtual
         virtual :some_method
      end
    end
  end
end

In the example, the concrete implementation of some_method from SomeModule will be overwritten by virtual :some_method from SomeOtherModule.

This always results in a malfunction, since the method being overwritten is the virtual method's concrete implementation. The protocol macro was added to address this circumstance, but the lack of an error when using the virtual and abstract macros remains a problem.

Proposed Behavior

The virtual and pure_virtual macros raise an error if a concrete implementation exists. The error message includes the source location of the concrete implementation.

@ntl
Copy link
Contributor

ntl commented Dec 29, 2023

This library has an outstanding problem that needs to be addressed before this can be considered.

@sbellware
Copy link
Contributor

@aaronjensen Do you remember off-hand what the issues were with Virtual and the manipulation of the ancestry? I remember something about is was so wrong, that we were considering decommissioning the library in its entirety.

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.

If virtual or pure_virtual is declared in a class that already has a concrete implementation, raise an error

3 participants