ecsharp icon indicating copy to clipboard operation
ecsharp copied to clipboard

'with' or quick binding operator bug

Open D0ctorWh0 opened this issue 4 years ago • 1 comments

Hi!

I came across your project and it looks very interesting. I played a bit with it and get an error when trying to use 'with' and quick binding operator.

When I write this EC# code

Point p = new Point(0, 0);
var point2 = new Point(2,2);

with (p)
{
    .X = 0;
    .Y = 1;
}

it generates valid C# code

Point p = new Point(0, 0);
var point2 = new Point(2, 2);
{
var tmp_10 = p;
tmp_10.X = 0;
tmp_10.Y = 1;
}

But when I try this EC# code

Point p = new Point(0, 0);
new Point(2,2)::point2;

with (p)
{
    .X = 0;
    .Y = 1;
}

it generates invalid C# code

Point p = new Point(0, 0);
var point2 = new Point(2, 2);
point2;
{
var tmp_10 = p;
tmp_10.X = 0;
tmp_10.Y = 1;
}

P.S. Why keeping braces from 'with' is C# code?

I tried to use only quick binding operator and it gives some error. Am I using it wrong?

D0ctorWh0 avatar Jan 31 '21 18:01 D0ctorWh0

I've reproduced the bug - including the variant where new P()::p; on a line by itself produces uncompilable code - and I should point out that with is not compatible with value types like Point, as the temporary variable is not ref. LeMP is not aware of the type system and cannot detect value types. (Potentially ref could be added on the temporary variable to fix the problem, but in other cases this could cause a compiler error). There's a note of caution in the documentation but I could have made it clearer...

qwertie avatar Feb 01 '21 19:02 qwertie