Comments (3)
But, yes- @Ruzihm did find a different issue- there are not good error messages for attempting to invoke an operator overload dynamically from an interface. These interfaces were meant only to be used as generic constraints, not for dynamic dispatch.
The issue is that the return type from these operator overloads is 'Self'. This is not allowed since 'Self' infers the type implementing this interface (the concrete type). If you are dynamically calling a Self-returning interface method on a boxed valuetype, then that return value would have to be boxed by the callee --- which I thought I couldn't allow since it infers heap allocation that no one will know to clean up, but now I realize it COULD be implemented with a side stack.
So, better error message for now, but dynamic dispatch for operator overloads is going in the "future features" pile - but with a fairly low priority.
from beef.
Shouldn't it rather be a different interface such as IOpSubtractable
? IOpNegatable
specifically defines the unary negate operator, e.g.:
IOpNegatable x = (Float)5.0;
IOpNegatable y = -x;
Console.Write("{}", (Float)y);
Which... actually doesn't even compile because "Operator can only be used on numeric types". What's with that?
But this works as expected:
using System;
namespace Program
{
class Foobar : IOpNegatable
{
public int value;
public this(int val)
{
value = val;
}
public static Self operator -(Self me)
{
let result = new Foobar();
result.value = -me.value;
return result;
}
override public void ToString(String strBuffer)
{
strBuffer..AppendF("{}",value);
}
}
class Program
{
public static void Main()
{
Foobar x = scope:: Foobar(5);
Foobar y = -x;
defer delete y;
Console.Write("{}", y);
Console.In.Read();
}
}
}
from beef.
Agreed after giving a bit more thought a new interface IOpSubtractable is the correct approach
from beef.
Related Issues (20)
- [Enhancement] rest/leftover function for StringSplitEnumerator HOT 1
- [Enhancement] Fixit: Generate All for switching on enums HOT 1
- Question about returning stack-allocated objects HOT 2
- [Crash] Calling generic method with optional argument where T : struct, new
- The console window is raised over any created windows when debugging
- LLVM Issue? HOT 2
- BeefLSP Bug HOT 2
- [Formatter] Valid code formatted to invalid code HOT 1
- Crash on compile when using defer with `->` operator overload HOT 1
- [IDE][Crash][Comptime] Accessing protected fields using [Friend] attribute directly from typeof(T) causes IDE to crash
- Crash on compile when using generic mixin with const String argument HOT 1
- Crashing in IDE when moving a line off the top or bottom of the file.
- maybe without distinguishing between class & struct ? HOT 6
- [Enhancement] Add indexers to the method list of the opened file HOT 1
- Can the compiled program support Windows XP HOT 1
- [BUG] IDE crashes with the provided mixin when repeatedly removing & writing second argument. HOT 1
- Getting invoke from function pointers with reflection doesn't work anymore HOT 2
- Bad syntax allowed
- Question: How do I get the processor time in Beef HOT 1
- Memory acess error when calling bound function on wasm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beef.