bool DeclarationAnalyzer::verifyProtocolFunction(const TypePtr& type, const TypePtr& protocol, const FunctionSymbolPtr& expected, bool supressError) { std::vector<SymbolPtr> results; int filter = FilterLookupInExtension | FilterRecursive; if(expected->hasFlags(SymbolFlagStatic)) filter |= FilterStaticMember; semanticAnalyzer->getMethodsFromType(type, expected->getName(), (MemberFilter)filter, results); TypePtr expectedType = expected->getType(); assert(expectedType != nullptr); //verify if they're the same type bool found = false; for(const SymbolPtr& func : results) { if(checkTypeConform(type, expectedType, func->getType())) { found = true; break; } } if(!found) { if(!supressError) { error(type->getReference(), Errors::E_TYPE_DOES_NOT_CONFORM_TO_PROTOCOL_UNIMPLEMENTED_FUNCTION_3, type->getName(), protocol->getName(), expected->getName()); } return false; } return true; }
void DeclarationAnalyzer::verifyProtocolFunction(const TypePtr& type, const TypePtr& protocol, const FunctionSymbolPtr& expected) { SymbolPtr sym = type->getMember(expected->getName()); TypePtr expectedType = expected->getType(); assert(expectedType != nullptr); if(!sym) { error(type->getReference(), Errors::E_TYPE_DOES_NOT_CONFORM_TO_PROTOCOL_UNIMPLEMENTED_FUNCTION_3, type->getName(), protocol->getName(), expected->getName()); return; } else if(const FunctionSymbolPtr& func = std::dynamic_pointer_cast<FunctionSymbol>(sym)) { //verify if they're the same type TypePtr funcType = func->getType(); assert(funcType != nullptr); if(!Type::equals(funcType, expectedType)) { error(type->getReference(), Errors::E_TYPE_DOES_NOT_CONFORM_TO_PROTOCOL_UNIMPLEMENTED_FUNCTION_3, type->getName(), protocol->getName(), expected->getName()); } return; } else if(FunctionOverloadedSymbolPtr funcs = std::dynamic_pointer_cast<FunctionOverloadedSymbol>(sym)) { //verify if they're the same type bool found = false; for(const FunctionSymbolPtr& func : *funcs) { if(Type::equals(func->getType(), expectedType)) { found = true; break; } } if(!found) error(type->getReference(), Errors::E_TYPE_DOES_NOT_CONFORM_TO_PROTOCOL_UNIMPLEMENTED_FUNCTION_3, type->getName(), protocol->getName(), expected->getName()); return; } else if(SymbolPlaceHolderPtr prop = std::dynamic_pointer_cast<SymbolPlaceHolder>(sym)) { } error(type->getReference(), Errors::E_TYPE_DOES_NOT_CONFORM_TO_PROTOCOL_UNIMPLEMENTED_FUNCTION_3, type->getName(), protocol->getName(), expected->getName()); }