mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
More extern constraints work
This commit is contained in:
parent
d35ef0e1e8
commit
35505d905a
7 changed files with 34 additions and 10 deletions
|
@ -443,7 +443,7 @@ namespace System
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*public static int Sign<T>(T value) where int : operator T <=> T, ICanBeNaN
|
||||
public static int Sign<T>(T value) where int : operator T <=> T where T : ICanBeNaN
|
||||
{
|
||||
if (value < default)
|
||||
return -1;
|
||||
|
@ -453,7 +453,7 @@ namespace System
|
|||
return 0;
|
||||
|
||||
Runtime.FatalError("Cannot be used on NaN");
|
||||
}*/
|
||||
}
|
||||
|
||||
public static int32 DivRem(int32 a, int32 b, out int32 result)
|
||||
{
|
||||
|
|
|
@ -212,12 +212,12 @@ bool BfMethodMatcher::IsMemberAccessible(BfTypeInstance* typeInst, BfTypeDef* de
|
|||
{
|
||||
if (mActiveTypeDef == NULL)
|
||||
mActiveTypeDef = mModule->GetActiveTypeDef();
|
||||
if (!typeInst->IsTypeMemberIncluded(declaringType, mActiveTypeDef, mModule))
|
||||
return false;
|
||||
|
||||
// This may not be completely correct - BUT if we don't have this then even Dictionary TKey's operator == won't be considered accessible
|
||||
if ((!mModule->IsInSpecializedSection()) && (mActiveTypeDef->mTypeDeclaration != NULL))
|
||||
{
|
||||
if (!typeInst->IsTypeMemberIncluded(declaringType, mActiveTypeDef, mModule))
|
||||
return false;
|
||||
if (!typeInst->IsTypeMemberAccessible(declaringType, mActiveTypeDef))
|
||||
return false;
|
||||
}
|
||||
|
@ -931,6 +931,11 @@ void BfMethodMatcher::CompareMethods(BfMethodInstance* prevMethodInstance, BfTyp
|
|||
auto prevMethodGenericParam = prevMethodInstance->mMethodInfoEx->mGenericParams[genericParamIdx];
|
||||
SET_BETTER_OR_WORSE(mModule->AreConstraintsSubset(prevMethodGenericParam, newMethodGenericParam), mModule->AreConstraintsSubset(newMethodGenericParam, prevMethodGenericParam));
|
||||
}
|
||||
|
||||
if ((!isBetter) && (!isWorse))
|
||||
{
|
||||
SET_BETTER_OR_WORSE(newMethodInstance->HasExternConstraints(), prevMethodInstance->HasExternConstraints());
|
||||
}
|
||||
}
|
||||
|
||||
if ((isBetter) || (isWorse))
|
||||
|
|
|
@ -12788,9 +12788,11 @@ bool BfModule::InDefinitionSection()
|
|||
|
||||
bool BfModule::IsInSpecializedGeneric()
|
||||
{
|
||||
if (mCurTypeInstance->IsSpecializedType())
|
||||
return true;
|
||||
if ((mCurMethodInstance == NULL) || (mCurMethodInstance->mIsUnspecialized))
|
||||
return false;
|
||||
return (mCurMethodInstance->GetNumGenericArguments() != 0) || (mCurTypeInstance->IsGenericTypeInstance());
|
||||
return (mCurMethodInstance->GetNumGenericArguments() != 0);
|
||||
}
|
||||
|
||||
bool BfModule::IsInSpecializedSection()
|
||||
|
|
|
@ -645,6 +645,11 @@ bool BfMethodInstance::IsSpecializedByAutoCompleteMethod()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool BfMethodInstance::HasExternConstraints()
|
||||
{
|
||||
return (mMethodInfoEx != NULL) && (mMethodInfoEx->mGenericParams.size() > mMethodInfoEx->mMethodGenericArguments.size());
|
||||
}
|
||||
|
||||
bool BfMethodInstance::HasParamsArray()
|
||||
{
|
||||
if (mParams.size() == 0)
|
||||
|
|
|
@ -865,6 +865,7 @@ public:
|
|||
bool IsSpecializedGenericMethod();
|
||||
bool IsSpecializedGenericMethodOrType();
|
||||
bool IsSpecializedByAutoCompleteMethod();
|
||||
bool HasExternConstraints();
|
||||
bool HasThis();
|
||||
bool HasExplicitThis();
|
||||
bool HasParamsArray();
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Tests
|
|||
|
||||
static
|
||||
{
|
||||
public static T Total<T>(this List<T> list) where T : IOpAddable
|
||||
public static T Total<T>(this List<T> list) where T : operator T + T
|
||||
{
|
||||
T total = default;
|
||||
for (let val in list)
|
||||
|
|
|
@ -116,9 +116,20 @@ namespace Tests
|
|||
return 3;
|
||||
}
|
||||
|
||||
public struct Entry
|
||||
{
|
||||
public static int operator<=>(Entry lhs, Entry rhs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
List<Entry> list = scope .();
|
||||
list.Sort();
|
||||
|
||||
ClassA ca = scope .();
|
||||
ClassB cb = scope .();
|
||||
Test.Assert(LibA.LibA0.GetVal(ca) == 123);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue