Wrap variable initializers in an ExpressionStatement
The compiler was emitting incorrect variable initialization code, resulting in a "=" BinaryOperatorExpression in a Statement position. This fix wraps it in an ExpressionStatement so it results in valid IL.
This commit is contained in:
parent
a2d847f1ef
commit
ae8284e86e
|
@ -1042,14 +1042,17 @@ export class Transformer {
|
|||
|
||||
private makeVariableInitializer(decl: VariableDeclaration<ast.Variable>): ast.Statement {
|
||||
contract.requires(!!decl.initializer, "decl", "Expected variable declaration to have an initializer");
|
||||
return this.withLocation(decl.node, {
|
||||
kind: ast.binaryOperatorExpressionKind,
|
||||
left: <ast.LoadLocationExpression>{
|
||||
kind: ast.loadLocationExpressionKind,
|
||||
name: decl.variable.name,
|
||||
},
|
||||
operator: "=",
|
||||
right: decl.initializer,
|
||||
return this.withLocation(decl.node, <ast.ExpressionStatement>{
|
||||
kind: ast.expressionStatementKind,
|
||||
expression: this.withLocation(decl.node, <ast.BinaryOperatorExpression>{
|
||||
kind: ast.binaryOperatorExpressionKind,
|
||||
left: <ast.LoadLocationExpression>{
|
||||
kind: ast.loadLocationExpressionKind,
|
||||
name: decl.variable.name,
|
||||
},
|
||||
operator: "=",
|
||||
right: decl.initializer,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -103,39 +103,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "w",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "w",
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
"column": 17
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 15
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 17
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -288,39 +302,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 4
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 5
|
||||
"column": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 8,
|
||||
"column": 8
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 10
|
||||
"column": 11
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -103,39 +103,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
"column": 17
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 15
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 17
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -103,39 +103,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
"column": 17
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 15
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 17
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -103,39 +103,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "v",
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 11
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 12
|
||||
"column": 17
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "other.ts",
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 15
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 17
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -39,39 +39,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "x",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "x",
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
"column": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
"column": 11
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -39,39 +39,53 @@
|
|||
"kind": "Block",
|
||||
"statements": [
|
||||
{
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "x",
|
||||
"kind": "ExpressionStatement",
|
||||
"expression": {
|
||||
"kind": "BinaryOperatorExpression",
|
||||
"left": {
|
||||
"kind": "LoadLocationExpression",
|
||||
"name": {
|
||||
"kind": "Identifier",
|
||||
"ident": "x",
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 12
|
||||
"column": 17
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "=",
|
||||
"right": {
|
||||
"kind": "NumberLiteral",
|
||||
"raw": "42",
|
||||
"value": 42,
|
||||
},
|
||||
"loc": {
|
||||
"file": "index.ts",
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
"column": 18
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue