1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-15 23:04:09 +02:00

Improved extern type constraints

This commit is contained in:
Brian Fiete 2020-08-10 13:29:05 -07:00
parent 99989d5472
commit 32cd6d8841
8 changed files with 280 additions and 85 deletions

View file

@ -1,3 +1,5 @@
#pragma warning disable 168
using System;
using System.Collections;
@ -32,6 +34,48 @@ namespace Tests
return Method2<Dictionary<K, V>.Enumerator, (K key, V value)>(param1.GetEnumerator());
}
struct StructA
{
}
class ClassA<T> where float : operator T * T where char8 : operator implicit T
{
public static float DoMul(T lhs, T rhs)
{
char8 val = lhs;
return lhs * rhs;
}
}
extension ClassA<T> where double : operator T - T where StructA : operator explicit T
{
public static double DoSub(T lhs, T rhs)
{
StructA sa = (StructA)lhs;
return lhs - rhs;
}
}
extension ClassA<T> where int16 : operator T + T where int8 : operator implicit T
{
public static double DoAdd(T lhs, T rhs)
{
int8 val = lhs;
double d = lhs * rhs;
return lhs + rhs;
}
}
public static void Test0<T>(T val)
where float : operator T * T where char8 : operator implicit T
where int16 : operator T + T where int8 : operator implicit T
{
ClassA<T> ca = scope .();
ClassA<T>.DoMul(val, val);
ClassA<T>.DoAdd(val, val);
}
[Test]
public static void TestBasics()
{