1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-14 14:24:10 +02:00

Fixed constraints error

This commit is contained in:
Brian Fiete 2020-09-12 09:24:01 -07:00
parent 95da04b202
commit a2920dce11
2 changed files with 7 additions and 6 deletions

View file

@ -171,7 +171,7 @@ bool BfDefBuilder::WantsNode(BfAstNode* wholeNode, BfAstNode* startNode, int add
static int sGenericParamIdx = 0; static int sGenericParamIdx = 0;
void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array<BfGenericParamDef*>& genericParams, Array<BfExternalConstraintDef>* externConstraintDefs, int outerGenericSize) void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array<BfGenericParamDef*>& genericParams, Array<BfExternalConstraintDef>* externConstraintDefs, int outerGenericSize, bool isInGeneric)
{ {
if (genericParamsDecl != NULL) if (genericParamsDecl != NULL)
{ {
@ -255,8 +255,8 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD
} }
else else
{ {
if (genericParams.IsEmpty()) if (!isInGeneric)
Fail("Constraints cannot be specified for non-generic types", genericConstraint); Fail("Constraints cannot be specified for non-generics", genericConstraint);
externConstraintDefs->Add(BfExternalConstraintDef()); externConstraintDefs->Add(BfExternalConstraintDef());
BfExternalConstraintDef* externConstraintDef = &externConstraintDefs->back(); BfExternalConstraintDef* externConstraintDef = &externConstraintDefs->back();
@ -596,7 +596,8 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
(methodDef->mMethodType == BfMethodType_Mixin) || (methodDef->mMethodType == BfMethodType_Mixin) ||
(methodDef->mMethodType == BfMethodType_Extension)) (methodDef->mMethodType == BfMethodType_Extension))
{ {
ParseGenericParams(methodDeclaration->mGenericParams, methodDeclaration->mGenericConstraintsDeclaration, methodDef->mGenericParams, &methodDef->mExternalConstraints, outerGenericSize); bool isGeneric = (methodDeclaration->mGenericParams != NULL) || (!mCurTypeDef->mGenericParamDefs.IsEmpty());
ParseGenericParams(methodDeclaration->mGenericParams, methodDeclaration->mGenericConstraintsDeclaration, methodDef->mGenericParams, &methodDef->mExternalConstraints, outerGenericSize, isGeneric);
} }
else else
{ {
@ -1660,7 +1661,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
int outerGenericSize = 0; int outerGenericSize = 0;
if (mCurTypeDef->mOuterType != NULL) if (mCurTypeDef->mOuterType != NULL)
outerGenericSize = (int)mCurTypeDef->mOuterType->mGenericParamDefs.size(); outerGenericSize = (int)mCurTypeDef->mOuterType->mGenericParamDefs.size();
ParseGenericParams(typeDeclaration->mGenericParams, typeDeclaration->mGenericConstraintsDeclaration, mCurTypeDef->mGenericParamDefs, &mCurTypeDef->mExternalConstraints, outerGenericSize); ParseGenericParams(typeDeclaration->mGenericParams, typeDeclaration->mGenericConstraintsDeclaration, mCurTypeDef->mGenericParamDefs, &mCurTypeDef->mExternalConstraints, outerGenericSize, !mCurTypeDef->mGenericParamDefs.IsEmpty());
BF_ASSERT(mCurTypeDef->mNameEx == NULL); BF_ASSERT(mCurTypeDef->mNameEx == NULL);

View file

@ -26,7 +26,7 @@ public:
HashContext* mSignatureHashCtx; HashContext* mSignatureHashCtx;
public: public:
void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array<BfGenericParamDef*>& genericParams, Array<BfExternalConstraintDef>* externConstraintDefs, int outerGenericSize); void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array<BfGenericParamDef*>& genericParams, Array<BfExternalConstraintDef>* externConstraintDefs, int outerGenericSize, bool isInGeneric);
BfProtection GetProtection(BfTokenNode* protectionToken); BfProtection GetProtection(BfTokenNode* protectionToken);
bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0); bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0);
//static BfNamedTypeReference* AllocTypeReference(BfSource* bfSource, const StringImpl& typeName); //static BfNamedTypeReference* AllocTypeReference(BfSource* bfSource, const StringImpl& typeName);