Skip to content

Commit

Permalink
fixed TraitBind Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LostbBlizzard committed Jul 20, 2024
1 parent b3eff43 commit c2fe73e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
3 changes: 2 additions & 1 deletion UCodeLang/UCodeLang/Compilation/Front/SystematicAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ class SystematicAnalysis



void Type_Convert(const TypeNode& V, TypeSymbol& Out);
void Type_Convert(const TypeNode& V, TypeSymbol& Out,bool allowtraitasself = false);

NullablePtr<Symbol> Generic_InstantiateOrFindGenericSymbol(const NeverNullPtr<Token> Token, const UseGenericsNode& GenericsVals, const String_view& Name);

Expand Down Expand Up @@ -1734,6 +1734,7 @@ class SystematicAnalysis
void Generic_TypeInstantiate_Tag(const NeverNullPtr<Symbol> Trait, const Vector<TypeSymbol>& Type);
void Generic_TypeInstantiate_ForType(const NeverNullPtr<Symbol> ForType, const Vector<TypeSymbol>& Type);

bool TypeHasTrait(const TypeSymbol& Type,SymbolID id);

EvaluatedEx Eval_MakeEx(const TypeSymbol& Type);
RawEvaluatedObject Eval_MakeExr(const TypeSymbol& Type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3880,6 +3880,24 @@ SystematicAnalysis::Get_FuncInfo SystematicAnalysis::Type_GetFunc(const ScopedN
}
}
}
else if (FuncGeneric.BaseOrRule.has_value())
{
auto& baseorrule = FuncGeneric.BaseOrRule.value();

if (auto base = baseorrule.Get_If<TypeSymbol>())
{
auto sym = Symbol_GetSymbol(base->_CustomTypeSymbol);

if (sym->Type == SymbolType::Trait_class)
{
bool typehastrait = TypeHasTrait(Input,base->_CustomTypeSymbol);
if (typehastrait)
{
isok = true;
}
}
}
}
else
{
isok = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void SystematicAnalysis::Generic_GenericAliasFixTypes(const GenericValuesNode& G
TypeSymbol type;
TypeNode typenode;
typenode._name._ScopedName = scoperule->_ScopedName;
Type_Convert(typenode, type);
Type_Convert(typenode, type,true);

base = type;
}
Expand Down Expand Up @@ -821,4 +821,4 @@ void SystematicAnalysis::Generic_GenericAliasFixTypes(const GenericValuesNode& G

UCodeLangFrontEnd

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ TypeSymbolID SystematicAnalysis::Type_GetTypeID(TypesEnum Type, SymbolID SymbolI
}
return R;
}
void SystematicAnalysis::Type_Convert(const TypeNode& V, TypeSymbol& Out)
void SystematicAnalysis::Type_Convert(const TypeNode& V, TypeSymbol& Out,bool allowtraitasself)
{
switch (V._name._ScopedName.back()._token->Type)
{
Expand Down Expand Up @@ -1676,7 +1676,7 @@ void SystematicAnalysis::Type_Convert(const TypeNode& V, TypeSymbol& Out)
}
else if (SybV->Type == SymbolType::Trait_class)
{
if (!V._IsDynamic)
if (!V._IsDynamic && allowtraitasself == false)
{
auto Token = V._name._ScopedName.back()._token;
LogError_TraitCantBeAlone(NeverNullptr(Token));
Expand Down Expand Up @@ -2271,6 +2271,29 @@ bool SystematicAnalysis::Type_IsUnMapType(const Symbol& Syb) const
return Syb.Type == SymbolType::Unmaped_Generic_Type;
}

bool SystematicAnalysis::TypeHasTrait(const TypeSymbol& Type,SymbolID id)
{
auto SybOp = Symbol_GetSymbol(Type);
if (SybOp.has_value())
{
auto Syb = SybOp.value();

if (Syb->Type == SymbolType::Type_class)
{
auto info = Syb->Get_Info<ClassInfo>();

for (auto& Item : info->_InheritedTypes)
{
if (Item.Syb->ID == id)
{
return true;
}
}
}

}
return false;
}
UCodeLangFrontEnd

#endif
#endif

0 comments on commit c2fe73e

Please sign in to comment.