mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed some struct* constraint checking
This commit is contained in:
parent
ecdc22920a
commit
69a597574d
3 changed files with 34 additions and 8 deletions
|
@ -7787,9 +7787,16 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
|
|||
}
|
||||
}
|
||||
|
||||
if (checkArgType->IsPointer())
|
||||
{
|
||||
auto ptrType = (BfPointerType*)checkArgType;
|
||||
checkArgType = ptrType->mElementType;
|
||||
}
|
||||
|
||||
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_New) != 0)
|
||||
{
|
||||
bool canAlloc = false;
|
||||
|
||||
if (auto checkTypeInst = checkArgType->ToTypeInstance())
|
||||
{
|
||||
if (checkTypeInst->IsObjectOrStruct())
|
||||
|
@ -7859,12 +7866,6 @@ bool BfModule::CheckGenericConstraints(const BfGenericParamSource& genericParamS
|
|||
if ((genericParamInst->mInterfaceConstraints.IsEmpty()) && (genericParamInst->mOperatorConstraints.IsEmpty()) && (genericParamInst->mTypeConstraint == NULL))
|
||||
return true;
|
||||
|
||||
if (checkArgType->IsPointer())
|
||||
{
|
||||
auto ptrType = (BfPointerType*)checkArgType;
|
||||
checkArgType = ptrType->mElementType;
|
||||
}
|
||||
|
||||
if (genericParamInst->mTypeConstraint != NULL)
|
||||
{
|
||||
bool constraintMatched = false;
|
||||
|
|
|
@ -3925,6 +3925,10 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt)
|
|||
{
|
||||
if (genericParamInst->mGenericParamFlags & (BfGenericParamFlag_Delete | BfGenericParamFlag_Var))
|
||||
return;
|
||||
if (genericParamInst->mGenericParamFlags & BfGenericParamFlag_StructPtr)
|
||||
return;
|
||||
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Struct) && (checkType->IsPointer()))
|
||||
return;
|
||||
Fail(StrFormat("Must add 'where %s : delete' constraint to generic parameter to delete generic type '%s'",
|
||||
genericParamInst->GetGenericParamDef()->mName.c_str(), TypeToString(val.mType).c_str()), deleteStmt->mExpression);
|
||||
return;
|
||||
|
|
|
@ -23,6 +23,16 @@ namespace Tests
|
|||
{
|
||||
class Generics
|
||||
{
|
||||
struct StructA : IDisposable
|
||||
{
|
||||
int mA = 123;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class ClassA : IDisposable, LibA.IVal
|
||||
{
|
||||
int LibA.IVal.Val
|
||||
|
@ -172,7 +182,7 @@ namespace Tests
|
|||
delete val;
|
||||
}
|
||||
|
||||
public static void Alloc2<T>() where T : new, delete, IDisposable, struct
|
||||
public static void Alloc2<T>() where T : new, IDisposable, struct
|
||||
{
|
||||
alloctype(T) val = new T();
|
||||
T* val2 = val;
|
||||
|
@ -180,6 +190,14 @@ namespace Tests
|
|||
delete val;
|
||||
}
|
||||
|
||||
public static void Alloc3<T>() where T : new, IDisposable, struct*
|
||||
{
|
||||
T val2 = default;
|
||||
if (val2 != null)
|
||||
val2.Dispose();
|
||||
delete val2;
|
||||
}
|
||||
|
||||
public class ClassE
|
||||
{
|
||||
public static Self Instance = new ClassE() ~ delete _;
|
||||
|
@ -311,6 +329,9 @@ namespace Tests
|
|||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
Alloc2<StructA>();
|
||||
Alloc3<StructA*>();
|
||||
|
||||
MethodD(scope => MethodC);
|
||||
|
||||
List<Entry> list = scope .();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue