Why did this compile?

  • Thread starter Thread starter John A. Bailo
  • Start date Start date
J

John A. Bailo

I got interrupted while changing a c# app, and left this statement in:


if(clearSource)
this.



Where clearSource is a bool. There was nothing after this, just a
period -- I had meant to add a method, but I didn't.

The program compiled and ran(!)
 
John A. Bailo said:
I got interrupted while changing a c# app, and left this statement in:

if(clearSource)
this.

Where clearSource is a bool. There was nothing after this, just a
period -- I had meant to add a method, but I didn't.

The program compiled and ran(!)

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

I can't reproduce it. I suspect you didn't see what you think you saw.
 
It looks like after the period, there can be spaces before finding a
method name. because just after the period that follows /this/ a few
lines down was a method call. I created a simple console app
demostrating the whole thing.


using System;

namespace thistest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//



}


public void myTest()
{
bool test=true;

if(test)
this.


myTest();



}

public void myCall()
{

return;
}


}
}
 
John A. Bailo said:
It looks like after the period, there can be spaces before finding a
method name.

Th at is c
o
r
rect;

SP

because just after the period that follows /this/ a few
lines down was a method call. I created a simple console app
demostrating the whole thing.


using System;

namespace thistest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//



}


public void myTest()
{
bool test=true;

if(test)
this.


myTest();



}

public void myCall()
{

return;
}


}
}




Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

I can't reproduce it. I suspect you didn't see what you think you saw.
 
John A. Bailo said:
It looks like after the period, there can be spaces before finding a
method name. because just after the period that follows /this/ a few
lines down was a method call. I created a simple console app
demostrating the whole thing.

Absolutely.

This is one reason for putting braces in for every "if" expression - it
wouldn't have compiled if it had been:

if(test)
{
this.
}

myTest();
 
Back
Top