code-d icon indicating copy to clipboard operation
code-d copied to clipboard

Local functions in constructor are perceived as member functions

Open AntonC9018 opened this issue 4 years ago • 6 comments

I'm having a similar problem as here, but it's even simpler. I assume the fix has not been merged into serve-d yet, or does it not cover my case?

Consider this code:

class A
{
	this()
	{
		void b() {}
		b();
	}
}

It squiggles b(); as warning:

a virtual call inside a constructor may lead to unexpected results in the derived classes.

AntonC9018 avatar Sep 05 '21 16:09 AntonC9018

are you using serve-d nightly?

WebFreak001 avatar Sep 05 '21 16:09 WebFreak001

@WebFreak001 Yes

AntonC9018 avatar Sep 05 '21 16:09 AntonC9018

I think that fix might not cover your issue there, happens for me too and I know I'm using the latest tagged dscanner release.

WebFreak001 avatar Sep 05 '21 16:09 WebFreak001

yes tested with dscanner ~master and the issue is there

WebFreak001 avatar Sep 05 '21 16:09 WebFreak001

On a related note, the following code gives the same warning for a();:

class A
{
    static void delegate() b;
    void a() {}
    this()
    {
        b = () { a(); };
    }
}

But if I change a() to this.a(), it doesn't.

AntonC9018 avatar Sep 05 '21 16:09 AntonC9018

I wonder if that is intentional, because this.a() is less ambiguous.

AntonC9018 avatar Sep 05 '21 16:09 AntonC9018