qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
176 stars 25 forks source link

'with' or quick binding operator bug #136

Open D0ctorWh0 opened 3 years ago

D0ctorWh0 commented 3 years ago

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?

qwertie commented 3 years ago

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...