diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index 1f9e2958..dd95b538 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -171,7 +171,7 @@ bool BfDefBuilder::WantsNode(BfAstNode* wholeNode, BfAstNode* startNode, int add static int sGenericParamIdx = 0; -void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize) +void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize, bool isInGeneric) { if (genericParamsDecl != NULL) { @@ -255,8 +255,8 @@ void BfDefBuilder::ParseGenericParams(BfGenericParamsDeclaration* genericParamsD } else { - if (genericParams.IsEmpty()) - Fail("Constraints cannot be specified for non-generic types", genericConstraint); + if (!isInGeneric) + Fail("Constraints cannot be specified for non-generics", genericConstraint); externConstraintDefs->Add(BfExternalConstraintDef()); BfExternalConstraintDef* externConstraintDef = &externConstraintDefs->back(); @@ -596,7 +596,8 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio (methodDef->mMethodType == BfMethodType_Mixin) || (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 { @@ -1660,7 +1661,7 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration) int outerGenericSize = 0; if (mCurTypeDef->mOuterType != NULL) 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); diff --git a/IDEHelper/Compiler/BfDefBuilder.h b/IDEHelper/Compiler/BfDefBuilder.h index d3be35cd..48c8ad73 100644 --- a/IDEHelper/Compiler/BfDefBuilder.h +++ b/IDEHelper/Compiler/BfDefBuilder.h @@ -26,7 +26,7 @@ public: HashContext* mSignatureHashCtx; public: - void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize); + void ParseGenericParams(BfGenericParamsDeclaration* genericParamsDecl, BfGenericConstraintsDeclaration* genericConstraints, Array& genericParams, Array* externConstraintDefs, int outerGenericSize, bool isInGeneric); BfProtection GetProtection(BfTokenNode* protectionToken); bool WantsNode(BfAstNode* wholeNode, BfAstNode* startNode = NULL, int addLen = 0); //static BfNamedTypeReference* AllocTypeReference(BfSource* bfSource, const StringImpl& typeName);