You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the Nemerle compiler silently accepts any operator overloads, even if they are not possible. For clarity the compiler should generate errors when an attempt is made to overload any of the operators implemented as macros.
The text was updated successfully, but these errors were encountered:
using System.Console;
namespace Test
{
publicmodule Main
{
public Main() : void
{
mutable test1 = Test(1);
def test2 = Test(2);
test1 += test2;
WriteLine($"Result=$(test1.Int)");
_ = ReadKey();
}
}
[Record]
publicclass Test
{
public Int : int { get; }
// 1st += overloadpublicstatic @+=(left : ref Test, right : Test) : void
{
WriteLine("called @+=(ref Test, Test) : void");
left = Test(left.Int + right.Int)
}
// 2nd += overlaodpublicstatic @+=(left : Test, right : Test) : Test
{
WriteLine("called @+=(Test, Test) : Test");
Test(left.Int + right.Int)
}
publicstatic @+(left : Test, right : Test) : Test
{
WriteLine("called @+(Test, Test) : Test");
Test(left.Int + right.Int)
}
}
}
Output when running:
called @+(Test, Test) : Test
Result=3
Now that I know that += is implemented as macro, I can easily understand the output.
To me the first version of the overload seems the more logical. The second would rather be def result = test1 += test2;. But in any case the macro just produces test1 = test1 + test2 and neither of the defined overloads can ever be called.
Currently the Nemerle compiler silently accepts any operator overloads, even if they are not possible. For clarity the compiler should generate errors when an attempt is made to overload any of the operators implemented as macros.
The text was updated successfully, but these errors were encountered: