Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Bug] "Step into" skips class constructor

Open Hiroko103 opened this issue 3 years ago • 2 comments

Version: Nightly (04/12/2021)

During debugging the "step into" command will only jump to TestClass' constructor if there is a breakpoint in it. Without it, the class constructor's instructions will be skipped altogether.

I tested it with a Debug build, so I assume no optimization took place that would cause this behaviour.

namespace beef_test
{
	class TestClass {
		public this {
			int a = 0; // If no breakpoint set here, step into will skip this line
		}
	}

	class Program
	{
		public static void Main(){
			TestClass c = scope TestClass();
		}
	}
}

Hiroko103 avatar May 04 '21 17:05 Hiroko103

Looking back at this issue, I've just found out what caused the problem. The TestClass' constructor is missing the parentheses.

With this function signature: public this() it works as expected (I don't have to set a breakpoint inside the constructor, to step into it with the debugger).

However, there is another strange behaviour. Without the parentheses, the constructor's protection level gets ignored, and behaves as if it were 'public'.

So with these following two declaration, it compiles and works fine (although the original debugger issue remains).

// Without specifying the protection level, 'private' is implied,
// which should cause compiler error when trying to initialize the class
this {} 

// The constructor gets called even with an explicit 'private' protection level
// (without any compiler warning or error)
private this {} 

Hiroko103 avatar Aug 22 '21 20:08 Hiroko103

Just noticed one more thing: Without the constructor parentheses, the method signature gets displayed as beef_test.TestClass.__BfInit() instead of beef_test.TestClass.this() in the IDE's method list:

image

Hiroko103 avatar Aug 22 '21 20:08 Hiroko103