1

Closed

struct member reference removes information

description

The short story is, if I do this:

float x = this.m_Container.m_Vector.x

where m_Container and m_Vector are structs, MicrosoftCCI seems to be removing the reference to this.m_Container entirely. CSharpSourceEmitter emits this:

float x = m_Vector.x; <--- COMPILE ERROR .. m_Vector only exists inside this.m_Container.



Here's a program that demonstrates the problem:

namespace Test
{
struct Vector
{
public float x, y, z;
}

struct Container
{
public Vector m_Vector;
}

public class Program
{
static Container m_Container;

public static void Main( string[] args )
{
float x = m_Container.m_Vector.x;
}
}
}



If I dig through the expression tree for the float x = m_Container.m_Vector.x line:

- the right side is an IBoundExpression where Instance is of type IAddressOf
- addressOf.Expression is an IAddressableExpression that is an IFieldReference referring to m_Vector

Closed Mar 19 at 10:54 PM by hermanv


comments

hermanv wrote Oct 3 2011 at 9:54 PM

See revision: 65680

YodaSkywalker wrote Oct 3 2011 at 7:03 PM

Sure. I attached a program to repro this:

1. Build bug.csproj.
2. Run the PeToTextViaCodeModel sample, passing bug.exe on the command line.
3. Open the outputted bug.txt file and note line 26 where it has "float x = m_Vector.x". That line should read "float x = container.m_Vector.x"

hermanv wrote Oct 3 2011 at 3:16 AM

Could you give a bit more context? Are you constructing an AST model and then finding that the projection to a Code Model is faulty? An actual test program that demonstrates the problem would be ideal.

Thanks.

YodaSkywalker wrote Oct 3 2011 at 2:04 AM

Note that it doesn't matter whether m_Container is a static member, a nonstatic member, or a local variable. It also doesn't matter whether I'm reading "x" or assigning to it. I simply can't access m_Container.m_Vector.x directly.


If Main() looks like this:

Container container = new Container();
float x = container.m_Vector.x;

.. the same problem happens.


The only workaround that I know of right now is to copy m_Vector into a temporary local, then reference -that-:

Container container = new Container();
Vector tempWorkaround = container.m_Vector;
float x = tempWorkaround.x;