Commit bb7b0cf3 authored by Milian Wolff's avatar Milian Wolff
Browse files

Don't report type mismatch warning if any type is mixed.

Mixed means it can be anything, so don't try to be clever.

BUG: 353808
parent 1b23f40e
......@@ -1493,19 +1493,17 @@ bool DeclarationBuilder::areTypesEqual(const AbstractType::Ptr& a, const Abstrac
}
const auto bIntegral = IntegralType::Ptr::dynamicCast(b);
if (bIntegral && bIntegral->dataType() == IntegralType::TypeString) {
// In QML/JS, a string can be converted to nearly everything else
if (bIntegral && (bIntegral->dataType() == IntegralType::TypeString || bIntegral->dataType() == IntegralType::TypeMixed)) {
// In QML/JS, a string can be converted to nearly everything else, similarly ignore mixed types
return true;
}
const auto aIntegral = IntegralType::Ptr::dynamicCast(a);
if (aIntegral && (aIntegral->dataType() == IntegralType::TypeString || aIntegral->dataType() == IntegralType::TypeMixed)) {
// In QML/JS, nearly everything can be to a string, similarly ignore mixed types
return true;
}
if (aIntegral && bIntegral) {
if ((aIntegral->dataType() == IntegralType::TypeMixed) ||
(bIntegral->dataType() == IntegralType::TypeMixed)) {
// Mixed types, don't try to be clever
return true;
}
if (isNumeric(aIntegral) && isNumeric(bIntegral)) {
// Casts between integral types is possible
return true;
......
function foo(arg)
{
}
function bar() {
foo(bar);
}
......@@ -73,6 +73,11 @@ void TestFiles::testQMLTypes()
parseAndCheck(TEST_FILES_DIR "/qmltypes/AnItem.qml", true);
}
void TestFiles::testTypeMismatchFalsePositives()
{
parseAndCheck(TEST_FILES_DIR "/type_mismatch_false_positives/code.js", true);
}
void TestFiles::testJSUsesBetweenFiles()
{
parseAndCheck(TEST_FILES_DIR "/js_cross_file_uses/js_variable_definition.js", false);
......
......@@ -34,6 +34,7 @@ private slots:
void testFiles_data();
void testFiles();
void testQMLTypes();
void testTypeMismatchFalsePositives();
private:
void parseAndCheck(const QString& fileName, bool check = true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment