Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
6.2.5, 6.3.1, 6.4.0 Beta2
-
84dd339e2e (qt/qtdeclarative/dev) 5c597dd0b8 (qt/qtdeclarative/6.3) 7c5570ca8c (qt/qtdeclarative/6.4) 5c597dd0b8 (qt/qtdeclarative/6.3.2) 5c597dd0b8 (qt/tqtc-qtdeclarative/6.3) 5c597dd0b8 (qt/tqtc-qtdeclarative/6.3.2), 13760c8d4 (tqtc/lts-6.2)
Description
Original code
import QtQml QtObject { function foo() { for (let i = 0; i < 5; ++i) console.log(i); } }
Problem 1
qmlformat wants to change 'let' to 'var' for no good reason. 'let' has block scope while 'var' does not.
import QtQml QtObject { function foo() { for (var i = 0; i < 5; ++i) console.log(i); } }
Problem 2
Inline formatting (`qmlformat -i main.qml`) fails with
qt.qmldom.writeOut: reparsed writeOut of /home/dev/main.qml has changes: - .components[""][0].objects[0].methods["foo"][0].body.astRelocatableDump value("<StatementList>\n <ForStatement forToken=\"for\" lparenToken=\"(\" rparenToken=\")\">\n <VariableDeclarationList commaToken=\"\">\n <PatternElement identifierToken=\"i\" bindingIdentifier=\"i\" type=\"5\" scope=\"2\" isForDeclaration=\"false\">\n <NumericLiteral value=\"0\" literalToken=\"0\">\n </NumericLiteral>\n </PatternElement>\n </VariableDeclarationList>\n <BinaryExpression op=\"15\" operatorToken=\"<\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n <NumericLiteral value=\"5\" literalToken=\"5\">\n </NumericLiteral>\n </BinaryExpression>\n <PreIncrementExpression incrementToken=\"++\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </PreIncrementExpression>\n <ExpressionStatement>\n <CallExpression lparenToken=\"(\" rparenToken=\")\">\n <FieldMemberExpression name=\"log\" dotToken=\".\" identifierToken=\"log\">\n <IdentifierExpression name=\"console\" identiferToken=\"console\">\n </IdentifierExpression>\n </FieldMemberExpression>\n <ArgumentList commaToken=\"\" isSpreadElement=\"false\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </ArgumentList>\n </CallExpression>\n </ExpressionStatement>\n </ForStatement>\n</StatementList>\n") + .components[""][0].objects[0].methods["foo"][0].body.astRelocatableDump value("<StatementList>\n <ForStatement forToken=\"for\" lparenToken=\"(\" rparenToken=\")\">\n <VariableDeclarationList commaToken=\"\">\n <PatternElement identifierToken=\"i\" bindingIdentifier=\"i\" type=\"5\" scope=\"1\" isForDeclaration=\"false\">\n <NumericLiteral value=\"0\" literalToken=\"0\">\n </NumericLiteral>\n </PatternElement>\n </VariableDeclarationList>\n <BinaryExpression op=\"15\" operatorToken=\"<\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n <NumericLiteral value=\"5\" literalToken=\"5\">\n </NumericLiteral>\n </BinaryExpression>\n <PreIncrementExpression incrementToken=\"++\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </PreIncrementExpression>\n <ExpressionStatement>\n <CallExpression lparenToken=\"(\" rparenToken=\")\">\n <FieldMemberExpression name=\"log\" dotToken=\".\" identifierToken=\"log\">\n <IdentifierExpression name=\"console\" identiferToken=\"console\">\n </IdentifierExpression>\n </FieldMemberExpression>\n <ArgumentList commaToken=\"\" isSpreadElement=\"false\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </ArgumentList>\n </CallExpression>\n </ExpressionStatement>\n </ForStatement>\n</StatementList>\n") qt.qmldom.writeOut: failure reformatting "main.qml" "Error while writing"
This error only occurs with the 'let' -> 'var' change, not with other types of changes. It should disappear when Problem 1 is fixed.
Attachments
Issue Links
- is duplicated by
-
QTBUG-108274 Qmlformat issue with let inside for loop
- Closed
For Gerrit Dashboard: QTBUG-105361 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
425203,3 | qmlformat: Preserve variable declaration scope type | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
426200,2 | qmlformat: Preserve variable declaration scope type | 6.3 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
426201,2 | qmlformat: Preserve variable declaration scope type | 6.4 | qt/qtdeclarative | Status: MERGED | +2 | 0 |
426202,4 | qmlformat: Preserve variable declaration scope type | tqtc/lts-6.2 | qt/tqtc-qtdeclarative | Status: MERGED | +2 | 0 |