Skip to content

Commit f347191

Browse files
committed
always evaluate rhs of assignments to underscore
1 parent b3580af commit f347191

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

compiler/prelude/prelude.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var $throwRuntimeError; /* set by package "runtime" */
3030
var $throwNilPointerError = function() { $throwRuntimeError("invalid memory address or nil pointer dereference"); };
3131
var $call = function(fn, rcvr, args) { return fn.apply(rcvr, args); };
3232
var $makeFunc = function(fn) { return function() { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments, []))), $emptyInterface); }; };
33+
var $unused = function(v) {};
3334
3435
var $mapArray = function(array, f) {
3536
var newArray = new array.constructor(array.length);

compiler/statements.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
358358
case len(s.Lhs) == 1 && len(s.Rhs) == 1:
359359
lhs := astutil.RemoveParens(s.Lhs[0])
360360
if isBlank(lhs) {
361-
if analysis.HasSideEffect(s.Rhs[0], c.p.Info.Info) {
362-
c.Printf("%s;", c.translateExpr(s.Rhs[0]))
363-
}
361+
c.Printf("$unused(%s);", c.translateExpr(s.Rhs[0]))
364362
return
365363
}
366364
c.Printf("%s", c.translateAssign(lhs, s.Rhs[0], s.Tok == token.DEFINE))
@@ -380,9 +378,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
380378
for i, rhs := range s.Rhs {
381379
tmpVars[i] = c.newVariable("_tmp")
382380
if isBlank(astutil.RemoveParens(s.Lhs[i])) {
383-
if analysis.HasSideEffect(rhs, c.p.Info.Info) {
384-
c.Printf("%s;", c.translateExpr(rhs))
385-
}
381+
c.Printf("$unused(%s);", c.translateExpr(rhs))
386382
continue
387383
}
388384
c.Printf("%s", c.translateAssign(c.newIdent(tmpVars[i], c.p.TypeOf(s.Lhs[i])), rhs, true))

0 commit comments

Comments
 (0)