Skip to content

Commit

Permalink
Set the type for unary expressions in v4.
Browse files Browse the repository at this point in the history
Previously unary expressions were being discarded because the type
was not set. Also add tests verifying the results.

Change-Id: Icbb493fbb6f036e59c8a4a1fe232c118312a63a5
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
  • Loading branch information
Michael Brasser authored and Qt by Nokia committed Feb 16, 2012
1 parent 2df9abf commit 64a5087
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/declarative/qml/v4/qv4ir_p.h
Expand Up @@ -306,7 +306,7 @@ struct Unop: Expr {

void init(AluOp op, Expr *expr)
{
this->typeForOp(op, expr);
this->type = this->typeForOp(op, expr);
this->op = op;
this->expr = expr;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/auto/declarative/v4/data/unaryMinus.qml
Expand Up @@ -7,12 +7,18 @@ Item {
property int test4: -i1.p1
property real test5: -i1.p3
property int test6: -i1.p3
property real test7: -i1.p4
property int test8: -i1.p4
property real test9: -i1.p5
property int test10: -i1.p5

QtObject {
id: i1
property real p1: -3.7
property int p2: 18
property real p3: -3.3
property int p4: -7
property real p5: 4.4
}
}

24 changes: 24 additions & 0 deletions tests/auto/declarative/v4/data/unaryPlus.qml
@@ -0,0 +1,24 @@
import QtQuick 2.0

Item {
property real test1: +i1.p2
property int test2: +i1.p2
property real test3: +i1.p1
property int test4: +i1.p1
property real test5: +i1.p3
property int test6: +i1.p3
property real test7: +i1.p4
property int test8: +i1.p4
property real test9: +i1.p5
property int test10: +i1.p5

QtObject {
id: i1
property real p1: -3.7
property int p2: 18
property real p3: -3.3
property int p4: -7
property real p5: 4.4
}
}

44 changes: 44 additions & 0 deletions tests/auto/declarative/v4/tst_v4.cpp
Expand Up @@ -71,6 +71,8 @@ private slots:
void qtbug_21883();
void qtbug_22816();
void stringComparison();
void unaryMinus();
void unaryPlus();

private:
QDeclarativeEngine engine;
Expand Down Expand Up @@ -304,6 +306,48 @@ void tst_v4::stringComparison()
delete o;
}

void tst_v4::unaryMinus()
{
QDeclarativeComponent component(&engine, testFileUrl("unaryMinus.qml"));

QObject *o = component.create();
QVERIFY(o != 0);

QCOMPARE(o->property("test1").toReal(), qreal(-18));
QCOMPARE(o->property("test2").toInt(), -18);
QCOMPARE(o->property("test3").toReal(), qreal(3.7));
QCOMPARE(o->property("test4").toInt(), 4);
QCOMPARE(o->property("test5").toReal(), qreal(3.3));
QCOMPARE(o->property("test6").toInt(), 3);
QCOMPARE(o->property("test7").toReal(), qreal(7));
QCOMPARE(o->property("test8").toInt(), 7);
QCOMPARE(o->property("test9").toReal(), qreal(-4.4));
QCOMPARE(o->property("test10").toInt(), -4);

delete o;
}

void tst_v4::unaryPlus()
{
QDeclarativeComponent component(&engine, testFileUrl("unaryPlus.qml"));

QObject *o = component.create();
QVERIFY(o != 0);

QCOMPARE(o->property("test1").toReal(), qreal(18));
QCOMPARE(o->property("test2").toInt(), 18);
QCOMPARE(o->property("test3").toReal(), qreal(-3.7));
QCOMPARE(o->property("test4").toInt(), -4);
QCOMPARE(o->property("test5").toReal(), qreal(-3.3));
QCOMPARE(o->property("test6").toInt(), -3);
QCOMPARE(o->property("test7").toReal(), qreal(-7));
QCOMPARE(o->property("test8").toInt(), -7);
QCOMPARE(o->property("test9").toReal(), qreal(4.4));
QCOMPARE(o->property("test10").toInt(), 4);

delete o;
}

QTEST_MAIN(tst_v4)

#include "tst_v4.moc"

0 comments on commit 64a5087

Please sign in to comment.