1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed some extension issues

This commit is contained in:
Brian Fiete 2020-06-05 16:16:14 -07:00
parent 34b846b11c
commit 4b15ad576f
2 changed files with 31 additions and 20 deletions

View file

@ -7210,6 +7210,9 @@ void BfCompiler::GenerateAutocompleteInfo()
} }
} }
if (methodInstance->mMethodDef->mMethodType == BfMethodType_Extension)
methodText += "(extension) ";
if (methodInstance->mMethodDef->mMethodType != BfMethodType_Ctor) if (methodInstance->mMethodDef->mMethodType != BfMethodType_Ctor)
{ {
if (methodInstance->mReturnType != NULL) if (methodInstance->mReturnType != NULL)
@ -7270,6 +7273,9 @@ void BfCompiler::GenerateAutocompleteInfo()
if (dispParamIdx > 0) if (dispParamIdx > 0)
methodText += ",\x1 "; methodText += ",\x1 ";
if ((paramIdx == 0) && (methodInstance->mMethodDef->mMethodType == BfMethodType_Extension))
continue;
auto type = methodInstance->GetParamType(paramIdx); auto type = methodInstance->GetParamType(paramIdx);
BfExpression* paramInitializer = methodInstance->GetParamInitializer(paramIdx); BfExpression* paramInitializer = methodInstance->GetParamInitializer(paramIdx);

View file

@ -1283,12 +1283,15 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
if ((mModule->mCompiler->mResolvePassData != NULL) && (!isFailurePass)) if ((mModule->mCompiler->mResolvePassData != NULL) && (!isFailurePass))
autoComplete = mModule->mCompiler->mResolvePassData->mAutoComplete; autoComplete = mModule->mCompiler->mResolvePassData->mAutoComplete;
if (checkMethod->mMethodType != BfMethodType_Extension)
{
if (((checkMethod->mIsStatic) && (!mAllowStatic)) || if (((checkMethod->mIsStatic) && (!mAllowStatic)) ||
((!checkMethod->mIsStatic) && (!mAllowNonStatic))) ((!checkMethod->mIsStatic) && (!mAllowNonStatic)))
{ {
if (!typeInstance->IsFunction()) if (!typeInstance->IsFunction())
autoComplete = NULL; autoComplete = NULL;
} }
}
if ((autoComplete != NULL) && (autoComplete->mIsCapturingMethodMatchInfo)) if ((autoComplete != NULL) && (autoComplete->mIsCapturingMethodMatchInfo))
{ {
@ -7326,12 +7329,14 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
else else
MakeBaseConcrete(target); MakeBaseConcrete(target);
BfType* callTargetType = curTypeInst;
if (methodDef->mMethodType == BfMethodType_Extension) if (methodDef->mMethodType == BfMethodType_Extension)
{ {
auto thisType = moduleMethodInstance.mMethodInstance->GetParamType(0); callTargetType = moduleMethodInstance.mMethodInstance->GetParamType(0);
curTypeInst = thisType->ToTypeInstance(); if ((callTargetType->IsRef()) && (target.IsAddr()) && (!target.IsReadOnly()) && (target.mType->IsValueType()))
if (curTypeInst == NULL) {
curTypeInst = mModule->mContext->mBfObjectType; target = BfTypedValue(target.mValue, mModule->CreateRefType(target.mType));
}
} }
BfTypedValue callTarget; BfTypedValue callTarget;
@ -7341,7 +7346,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
if (target) if (target)
callTarget = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), targetTypeInst); callTarget = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), targetTypeInst);
} }
else if (targetTypeInst == curTypeInst) else if (targetTypeInst == callTargetType)
{ {
if ((target) && (methodDef->HasNoThisSplat())) if ((target) && (methodDef->HasNoThisSplat()))
{ {
@ -7361,10 +7366,10 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
{ {
if (methodMatcher.mFakeConcreteTarget) if (methodMatcher.mFakeConcreteTarget)
{ {
BF_ASSERT(curTypeInst->IsInterface()); BF_ASSERT(callTargetType->IsInterface());
callTarget = mModule->GetDefaultTypedValue(mModule->CreateConcreteInterfaceType(curTypeInst)); callTarget = mModule->GetDefaultTypedValue(mModule->CreateConcreteInterfaceType(callTargetType->ToTypeInstance()));
} }
else if (((target.mType->IsGenericParam()) || (target.mType->IsConcreteInterfaceType())) && (curTypeInst->IsInterface())) else if (((target.mType->IsGenericParam()) || (target.mType->IsConcreteInterfaceType())) && (callTargetType->IsInterface()))
{ {
// Leave as generic // Leave as generic
callTarget = target; callTarget = target;
@ -7373,7 +7378,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
{ {
bool handled = false; bool handled = false;
if ((target.mType->IsTypedPrimitive()) && (curTypeInst->IsTypedPrimitive())) if ((target.mType->IsTypedPrimitive()) && (callTargetType->IsTypedPrimitive()))
{ {
handled = true; handled = true;
callTarget = target; callTarget = target;
@ -7381,10 +7386,10 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
else if ((target.mType->IsStructOrStructPtr()) || (target.mType->IsTypedPrimitive())) else if ((target.mType->IsStructOrStructPtr()) || (target.mType->IsTypedPrimitive()))
{ {
//BF_ASSERT(target.IsAddr()); //BF_ASSERT(target.IsAddr());
if (curTypeInst->IsObjectOrInterface()) if (callTargetType->IsObjectOrInterface())
{ {
// Box it // Box it
callTarget = mModule->Cast(targetSrc, target, curTypeInst, BfCastFlags_Explicit); callTarget = mModule->Cast(targetSrc, target, callTargetType, BfCastFlags_Explicit);
handled = true; handled = true;
} }
else else
@ -7398,7 +7403,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
if (!handled) if (!handled)
{ {
// Could we have just unconditionally done this? // Could we have just unconditionally done this?
callTarget = mModule->Cast(targetSrc, target, curTypeInst, BfCastFlags_Explicit); callTarget = mModule->Cast(targetSrc, target, callTargetType, BfCastFlags_Explicit);
} }
} }
} }
@ -7424,7 +7429,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
identifierNode = qualifiedNameNode->mRight; identifierNode = qualifiedNameNode->mRight;
if ((identifierNode != NULL) && (methodDef->mIdx >= 0) && (!isIndirectMethodCall)) if ((identifierNode != NULL) && (methodDef->mIdx >= 0) && (!isIndirectMethodCall))
{ {
mModule->mCompiler->mResolvePassData->HandleMethodReference(identifierNode, curTypeInst->mTypeDef, methodDef); mModule->mCompiler->mResolvePassData->HandleMethodReference(identifierNode, moduleMethodInstance.mMethodInstance->GetOwner()->mTypeDef, methodDef);
auto autoComplete = GetAutoComplete(); auto autoComplete = GetAutoComplete();
if ((autoComplete != NULL) && (autoComplete->IsAutocompleteNode(identifierNode))) if ((autoComplete != NULL) && (autoComplete->IsAutocompleteNode(identifierNode)))
{ {
@ -7453,7 +7458,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
if (autoComplete->mDefType == NULL) if (autoComplete->mDefType == NULL)
{ {
autoComplete->mDefMethod = methodDef; autoComplete->mDefMethod = methodDef;
autoComplete->mDefType = curTypeInst->mTypeDef; autoComplete->mDefType = moduleMethodInstance.mMethodInstance->GetOwner()->mTypeDef;
} }
if (autoComplete->mResolveType == BfResolveType_GetResultString) if (autoComplete->mResolveType == BfResolveType_GetResultString)