question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Commands w/ body defined in abstract classes aren't registered in subclasses unless virtual & overriden

See original GitHub issue

Summary

Commands declared in abstract classes extending BaseCommandModule do not propagate into their subclasses unless they are implemented or overriden in the subclass. This is both a bug report and a feature request, since it seems to be an oversight.

Details

Expected behavior

Registering a command in an abstract class, the command is propagated into whatever modules inherit that class

Actual behavior

The registered command doesn’t appear in the subclass.

Steps to reproduce

    public abstract class BaseTestModule : BaseCommandModule
    {
        // works: subclass is required to override the method, and the command is registered there
        [Command("atest")]
        public abstract Task Test1(CommandContext ctx);

        // works only if the subclass registers an `override` method for it
        [Command("atest2")]
        public virtual Task Test2(CommandContext ctx)
        {
            Console.WriteLine("Super");
            return Task.CompletedTask;
        }

        // doesn't work, method is not registered in the subclass
        [Command("atest3")]
        public Task Test3(CommandContext ctx)
        {
            Console.WriteLine("Super");
            return Task.CompletedTask;
        }
    }

    [Group("test")]
    public class TestImplementation : BaseTestModule
    {
        // works, will print test1
        public override Task Test1(CommandContext ctx)
        {
            Console.WriteLine("test1");
            return Task.CompletedTask;
        }

        // works, will print test2
        public override Task Test2(CommandContext ctx)
        {
            Console.WriteLine("test2");
            return Task.CompletedTask;
        }
        
        // atest3 doesn't work, doesn't print anything
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
uwxcommented, Jul 2, 2018

It’s still an issue, I just wrote the wrong steps to reproduce it.

0reactions
Emzi0767commented, Jul 3, 2018

This is intentional.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem creating abstract class with no virtual pure ...
I want to create a class that is a subclass of two classes that have a common virtual base class. Furthermore, I want...
Read more >
What happens if the subclass does not override abstract ...
What happens if the subclass does not override abstract methods in java - A method which does not have body is known as...
Read more >
Is inheriting from a non-abstract class bad OOP?
The problem is that inheriting from a class with no virtual methods, will cause you problems if you inherit from it and overwrite...
Read more >
Class Abstraction - Manual
PHP has abstract classes and methods. Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method...
Read more >
Pure Virtual Functions and Abstract Classes in C++
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found