| 3089 | } |
| 3090 | |
| 3091 | MemberList::Member TypeChecker::resolveOverloads(MemberAccess const& _memberAccess) const |
| 3092 | { |
| 3093 | Type const* owningObjectType = type(_memberAccess.expression()); |
| 3094 | ASTString const& memberName = _memberAccess.memberName(); |
| 3095 | |
| 3096 | // Retrieve the types of the arguments if this is used to call a function. |
| 3097 | auto const& arguments = _memberAccess.annotation().arguments; |
| 3098 | MemberList::MemberMap possibleMembers = owningObjectType->members(currentDefinitionScope()).membersByName(memberName); |
| 3099 | size_t const possibleMemberCountBeforeOverloading = possibleMembers.size(); |
| 3100 | if (possibleMemberCountBeforeOverloading >= 2 && arguments) |
| 3101 | { |
| 3102 | // do overload resolution |
| 3103 | for (auto it = possibleMembers.begin(); it != possibleMembers.end();) |
| 3104 | { |
| 3105 | if ( |
| 3106 | it->type->category() == Type::Category::Function && |
| 3107 | !dynamic_cast<FunctionType const&>(*it->type).canTakeArguments(*arguments, owningObjectType) |
| 3108 | ) |
| 3109 | it = possibleMembers.erase(it); |
| 3110 | else |
| 3111 | ++it; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | if (possibleMembers.empty()) |
| 3116 | { |
| 3117 | auto [errorID, errorMsg] = diagnoseUnresolvedMemberAccess(_memberAccess, possibleMemberCountBeforeOverloading); |
| 3118 | m_errorReporter.fatalTypeError(errorID, _memberAccess.location(), errorMsg); |
| 3119 | } |
| 3120 | else if (possibleMembers.size() >= 2) |
| 3121 | m_errorReporter.fatalTypeError( |
| 3122 | 6675_error, |
| 3123 | _memberAccess.location(), |
| 3124 | fmt::format( |
| 3125 | R"(Member "{}" not unique after argument-dependent lookup in {}{})", |
| 3126 | memberName, |
| 3127 | owningObjectType->humanReadableName(), |
| 3128 | memberName == "value" ? R"( - did you forget the "payable" modifier?)" : "." |
| 3129 | ) |
| 3130 | ); |
| 3131 | |
| 3132 | return possibleMembers.front(); |
| 3133 | } |
| 3134 | |
| 3135 | std::pair<ErrorId, std::string> TypeChecker::diagnoseUnresolvedMemberAccess( |
| 3136 | MemberAccess const& _memberAccess, |
nothing calls this directly
no test coverage detected