Permalink
Browse files

always evaluate rhs of assignments to underscore

  • Loading branch information...
1 parent b3580af commit f3471911039c5eec1b0ea655c810e25cd736560f @neelance neelance committed Jan 21, 2017
Showing with 3 additions and 6 deletions.
  1. +1 −0 compiler/prelude/prelude.go
  2. +2 −6 compiler/statements.go
@@ -30,6 +30,7 @@ var $throwRuntimeError; /* set by package "runtime" */
var $throwNilPointerError = function() { $throwRuntimeError("invalid memory address or nil pointer dereference"); };
var $call = function(fn, rcvr, args) { return fn.apply(rcvr, args); };
var $makeFunc = function(fn) { return function() { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments, []))), $emptyInterface); }; };
+var $unused = function(v) {};
var $mapArray = function(array, f) {
var newArray = new array.constructor(array.length);
@@ -358,9 +358,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
case len(s.Lhs) == 1 && len(s.Rhs) == 1:
lhs := astutil.RemoveParens(s.Lhs[0])
if isBlank(lhs) {
- if analysis.HasSideEffect(s.Rhs[0], c.p.Info.Info) {
- c.Printf("%s;", c.translateExpr(s.Rhs[0]))
- }
+ c.Printf("$unused(%s);", c.translateExpr(s.Rhs[0]))
return
}
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) {
for i, rhs := range s.Rhs {
tmpVars[i] = c.newVariable("_tmp")
if isBlank(astutil.RemoveParens(s.Lhs[i])) {
- if analysis.HasSideEffect(rhs, c.p.Info.Info) {
- c.Printf("%s;", c.translateExpr(rhs))
- }
+ c.Printf("$unused(%s);", c.translateExpr(rhs))
continue
}
c.Printf("%s", c.translateAssign(c.newIdent(tmpVars[i], c.p.TypeOf(s.Lhs[i])), rhs, true))

1 comment on commit f347191

@shurcooL
Member

For reference, this fixed #551.

Please sign in to comment.