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

Property visibility fixes for default interface methods

This commit is contained in:
Brian Fiete 2023-01-13 07:01:54 -05:00
parent 2746a53839
commit 16de3a14a4
5 changed files with 45 additions and 11 deletions

View file

@ -19050,7 +19050,7 @@ BfModuleMethodInstance BfExprEvaluator::GetPropertyMethodInstance(BfMethodDef* m
checkType = mModule->GetWrappedStructType(checkType); checkType = mModule->GetWrappedStructType(checkType);
if ((checkType != NULL) && (checkType->IsTypeInstance())) if ((checkType != NULL) && (checkType->IsTypeInstance()))
{ {
auto activeTypeDef = mModule->GetActiveTypeDef(); auto activeTypeDef = mModule->GetActiveTypeDef(NULL, false, true);
BfTypeInterfaceEntry* bestIFaceEntry = NULL; BfTypeInterfaceEntry* bestIFaceEntry = NULL;
bool checkedUnderlying = false; bool checkedUnderlying = false;
@ -19213,6 +19213,11 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
} }
} }
if (mModule->mCurMethodInstance->mIsForeignMethodDef)
{
NOP;
}
if (!handled) if (!handled)
{ {
SetAndRestoreValue<BfFunctionBindResult*> prevFunctionBindResult(mFunctionBindResult, NULL); SetAndRestoreValue<BfFunctionBindResult*> prevFunctionBindResult(mFunctionBindResult, NULL);

View file

@ -1949,7 +1949,7 @@ public:
BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags); BfType* ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTypeRef, BfPopulateType populateType, BfResolveTypeRefFlags resolveFlags);
void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef); void ShowAmbiguousTypeError(BfAstNode* refNode, BfTypeDef* typeDef, BfTypeDef* otherTypeDef);
void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams); void ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericParams);
BfTypeDef* GetActiveTypeDef(BfTypeInstance* typeInstanceOverride = NULL, bool useMixinDecl = false); // useMixinDecl is useful for type lookup, but we don't want the decl project to limit what methods the user can call BfTypeDef* GetActiveTypeDef(BfTypeInstance* typeInstanceOverride = NULL, bool useMixinDecl = false, bool useForeignImpl = false); // useMixinDecl is useful for type lookup, but we don't want the decl project to limit what methods the user can call
BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error, BfTypeLookupResultCtx* lookupResultCtx = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error, BfTypeLookupResultCtx* lookupResultCtx = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0); BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);

View file

@ -9921,7 +9921,7 @@ void BfModule::ShowGenericArgCountError(BfAstNode* typeRef, int wantedGenericPar
Fail(StrFormat("Too few generic parameters, expected %d more", -genericArgDiffCount), lastNode); Fail(StrFormat("Too few generic parameters, expected %d more", -genericArgDiffCount), lastNode);
} }
BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool useMixinDecl) BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool useMixinDecl, bool useForeignImpl)
{ {
BfTypeDef* useTypeDef = NULL; BfTypeDef* useTypeDef = NULL;
BfTypeInstance* typeInstance = (typeInstanceOverride != NULL) ? typeInstanceOverride : mCurTypeInstance; BfTypeInstance* typeInstance = (typeInstanceOverride != NULL) ? typeInstanceOverride : mCurTypeInstance;
@ -9932,6 +9932,12 @@ BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool
if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL) && (useMixinDecl)) if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL) && (useMixinDecl))
useTypeDef = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->GetDefinition(); useTypeDef = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->GetDefinition();
else if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mDeclaringType != NULL)) else if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mDeclaringType != NULL))
{
if ((mCurMethodInstance->mIsForeignMethodDef) && (useForeignImpl))
{
// Use the concrete impl typeDef, not the foreign method typedecl (the interface)
}
else
{ {
auto declTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType; auto declTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType;
useTypeDef = declTypeDef->GetDefinition(true); useTypeDef = declTypeDef->GetDefinition(true);
@ -9939,6 +9945,8 @@ BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool
{ {
// Always consider methods to belong to the primary type declaration // Always consider methods to belong to the primary type declaration
useTypeDef = useTypeDef->mPartials[0]; useTypeDef = useTypeDef->mPartials[0];
}
} }
} }
else if (mContext->mCurTypeState != NULL) else if (mContext->mCurTypeState != NULL)
@ -14981,7 +14989,7 @@ bool BfModule::TypeIsSubTypeOf(BfTypeInstance* srcType, BfTypeInstance* wantType
if (checkAccessibility) if (checkAccessibility)
{ {
if (checkActiveTypeDef == NULL) if (checkActiveTypeDef == NULL)
checkActiveTypeDef = GetActiveTypeDef(NULL, false); checkActiveTypeDef = GetActiveTypeDef(NULL, false, true);
// We need to be lenient when validating generic constraints // We need to be lenient when validating generic constraints
// Otherwise "T<A> where T : IB" declared in a lib won't be able to match a type B in a using project 'C', // Otherwise "T<A> where T : IB" declared in a lib won't be able to match a type B in a using project 'C',

View file

@ -4,6 +4,19 @@ using System.Diagnostics;
namespace LibA namespace LibA
{ {
public interface ITaggable
{
public String Tag
{
get;
}
public bool MatchesTag(String tag)
{
return Tag.Equals(tag);
}
}
struct LibAStruct struct LibAStruct
{ {
int mA; int mA;

View file

@ -405,6 +405,14 @@ namespace Tests
public static String Serialize(Self value); public static String Serialize(Self value);
} }
public class EngineTag : LibA.ITaggable
{
public String Tag
{
get => "ET";
}
}
[Test] [Test]
public static void TestDefaults() public static void TestDefaults()
{ {