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

Fixed error messages for methods with extern constraints in variations

This commit is contained in:
Brian Fiete 2020-08-04 10:30:25 -07:00
parent c7393865b4
commit 92d3ab6ca9
3 changed files with 64 additions and 10 deletions

View file

@ -196,6 +196,12 @@ void BfMethodMatcher::Init(/*SizedArrayImpl<BfResolvedArg>& arguments, */BfSized
for (BfTypeReference* genericArg : *methodGenericArguments)
{
auto genericArgType = mModule->ResolveTypeRef(genericArg);
if (genericArgType->IsGenericParam())
{
auto genericParamInstance = mModule->GetGenericParamInstance((BfGenericParamType*)genericArgType);
if ((genericParamInstance->mGenericParamFlags & BfGenericParamFlag_Var) != 0)
mHasVarArguments = true;
}
mExplicitMethodGenericArguments.push_back(genericArgType);
}
mHadExplicitGenericArguments = true;
@ -13023,7 +13029,12 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
{
checkMethodGenericArgs = &methodMatcher.mBestMethodGenericArguments;
genericArg = genericParams->mExternType;
genericArg = mModule->ResolveGenericType(genericArg, NULL, checkMethodGenericArgs);
auto owner = methodInstance.mMethodInstance->GetOwner();
BfTypeVector* typeGenericArguments = NULL;
if (owner->mGenericTypeInfo != NULL)
typeGenericArguments = &owner->mGenericTypeInfo->mTypeGenericArguments;
genericArg = mModule->ResolveGenericType(genericArg, typeGenericArguments, checkMethodGenericArgs);
}
if (genericArg->IsVar())
@ -13039,8 +13050,8 @@ BfModuleMethodInstance BfExprEvaluator::GetSelectedMethod(BfAstNode* targetSrc,
// Note: don't pass methodMatcher.mBestMethodGenericArguments into here, this method is already specialized
BfError* error = NULL;
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance.mMethodInstance), genericArg, paramSrc, genericParams, checkMethodGenericArgs,
failed ? NULL : &error))
if (!mModule->CheckGenericConstraints(BfGenericParamSource(methodInstance.mMethodInstance), genericArg, paramSrc, genericParams, NULL,
failed ? NULL : &error))
{
if (methodInstance.mMethodInstance->IsSpecializedGenericMethod())
{

View file

@ -6878,8 +6878,7 @@ String BfModule::GenericParamSourceToString(const BfGenericParamSource & generic
{
if (genericParamSource.mMethodInstance != NULL)
{
auto methodInst = GetUnspecializedMethodInstance(genericParamSource.mMethodInstance);
SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mCurMethodInstance, methodInst);
auto methodInst = GetUnspecializedMethodInstance(genericParamSource.mMethodInstance);
return MethodToString(methodInst);
}
else
@ -9598,6 +9597,8 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
type = ResolveGenericType(type, NULL, methodGenericArgs);
if ((type == NULL) || (!type->IsUnspecializedTypeVariation()))
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
if (allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
String methodName;
if ((methodNameFlags & BfMethodNameFlag_OmitTypeName) == 0)
@ -11289,13 +11290,15 @@ bool BfModule::CompareMethodSignatures(BfMethodInstance* methodA, BfMethodInstan
else if (methodA->mMethodDef->mName != methodB->mMethodDef->mName)
return false;
if (methodA->mMethodDef->mCheckedKind != methodB->mMethodDef->mCheckedKind)
return false;
return false;
if ((methodA->mMethodDef->mMethodType == BfMethodType_Mixin) != (methodB->mMethodDef->mMethodType == BfMethodType_Mixin))
return false;
if (methodA->mMethodDef->mMethodType == BfMethodType_Ctor)
{
if (methodA->mMethodDef->mIsStatic != methodB->mMethodDef->mIsStatic)
return false;
}
}
if (methodA->mMethodDef->mMethodType == BfMethodType_Operator)
{
@ -15501,7 +15504,8 @@ void BfModule::EmitTupleToStringBody()
if (fieldValue.mType->IsObjectOrInterface())
{
BF_ASSERT(!fieldValue.IsAddr());
fieldValue = LoadValue(fieldValue);
BF_ASSERT(!fieldValue.IsAddr());
SizedArray<BfIRValue, 2> args;
args.Add(mBfIRBuilder->CreateBitCast(fieldValue.mValue, mBfIRBuilder->MapType(mContext->mBfObjectType)));
auto stringDestVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]);
@ -19838,9 +19842,16 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
BfAutoComplete* bfAutocomplete = NULL;
if (mCompiler->mResolvePassData != NULL)
bfAutocomplete = mCompiler->mResolvePassData->mAutoComplete;
if ((methodDeclaration != NULL) && (methodDeclaration->ToString().Contains("//TEST")))
{
NOP;
}
if (methodInstance->mMethodInfoEx != NULL)
{
BfTypeInstance* unspecializedTypeInstance = NULL;
for (int genericParamIdx = 0; genericParamIdx < (int)methodInstance->mMethodInfoEx->mGenericParams.size(); genericParamIdx++)
{
auto genericParam = methodInstance->mMethodInfoEx->mGenericParams[genericParamIdx];
@ -19850,8 +19861,15 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
}
else
{
if (unspecializedTypeInstance == NULL)
unspecializedTypeInstance = GetUnspecializedTypeInstance(mCurTypeInstance);
auto externConstraintDef = genericParam->GetExternConstraintDef();
genericParam->mExternType = ResolveTypeRef(externConstraintDef->mTypeRef);
// Resolve in the unspecialized type, then resolve the generic later. This fixes ambiguity where the type is specialized by a method generic arg
{
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, unspecializedTypeInstance);
genericParam->mExternType = ResolveTypeRef(externConstraintDef->mTypeRef);
}
auto autoComplete = mCompiler->GetAutoComplete();
if (autoComplete != NULL)