void QPropertyTypeMismatch::checkMethodAgainstProperty()

in src/checks/manuallevel/qproperty-type-mismatch.cpp [111:171]


void QPropertyTypeMismatch::checkMethodAgainstProperty(const Property &prop, const CXXMethodDecl &method, const std::string &methodName)
{
    auto error_begin = [&] {
        return "Q_PROPERTY '" + prop.name + "' of type '" + prop.type + "' is mismatched with ";
    };

    if (prop.read == methodName) {
        std::string retTypeStr;
        if (!typesMatch(prop.type, method.getReturnType(), retTypeStr)) {
            emitWarning(&method, error_begin() + "method '" + methodName + "' of return type '" + retTypeStr + "'");
        }
    } else if (prop.write == methodName) {
        switch (method.getNumParams()) {
        case 0:
            emitWarning(&method, error_begin() + "method '" + methodName + "' with no parameters");
            break;
        case 1: {
            std::string parmTypeStr;
            if (!typesMatch(prop.type, method.getParamDecl(0)->getType(), parmTypeStr)) {
                emitWarning(&method, error_begin() + "method '" + methodName + "' with parameter of type '" + parmTypeStr + "'");
            }
            break;
        }
        default:
            // Commented out: Too verbose and it's not a bug, maybe wrap with an option for the purists
            // emitWarning(&method, error_begin() + "method '" + methodName + "' with too many parameters");
            break;
        }
    } else if (prop.notify == methodName) {
        switch (method.getNumParams()) {
        case 0:
            break;
        case 2: {
            /*
             // Commented out: Too verbose and it's not a bug, maybe wrap with an option for the purists
            auto param1TypeStr = cleanupType(method.getParamDecl(1)->getType());
            if(param1TypeStr.find("QPrivateSignal") == std::string::npos)
            {
                emitWarning(&method, error_begin() + "signal '" + methodName + "' with too many parameters" + param1TypeStr);
                break;
            }

            // We want to check the first parameter too :
            [[fallthrough]];*/
        }
        case 1: {
            std::string param0TypeStr;
            if (!typesMatch(prop.type, method.getParamDecl(0)->getType(), param0TypeStr)) {
                const bool isPrivateSignal = param0TypeStr.find("QPrivateSignal") != std::string::npos;
                if (!isPrivateSignal) {
                    emitWarning(&method, error_begin() + "signal '" + methodName + "' with parameter of type '" + param0TypeStr + "'");
                }
            }
            break;
        }
        default: {
            break;
        }
        }
    }
}