Skip to content

Commit

Permalink
fixed #190; don't reuse reference variables
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Nov 13, 2012
1 parent 630ffa3 commit 3a85ac1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,7 @@ exports.Pipe = Pipe = (function(superclass){
? Arr()
: JS(ref), output);
} else {
this.temps = [ref = o.scope.temporary('x')];
ref = o.scope.temporary('x');
}
if (input instanceof Pipe) {
input.ref = ref;
Expand All @@ -3169,8 +3169,7 @@ exports.Pipe = Pipe = (function(superclass){
}
o.level && (o.level = LEVEL_PAREN);
code = input.compile(o);
o.ref = new String(ref);
out = Block(output).compile(o);
out = Block(output).compile((o.ref = new String(ref), o));
if (this.implicit && !o.ref.erred) {
this.carp("unreferred cascadee");
}
Expand Down
5 changes: 2 additions & 3 deletions src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -1933,14 +1933,13 @@ class exports.Pipe extends Node
output.=makeReturn @ret
if ref
then output = Assign (if @cascade then Arr! else JS ref), output
else @temps = [ref = o.scope.temporary \x]
else ref = o.scope.temporary \x
if input instanceof Pipe
then input <<< {ref}
else input = Assign JS(ref), input
o.level &&= LEVEL_PAREN
code = input.compile o
o.ref = new String ref
out = Block output .compile o
out = Block output .compile o <<< ref: new String ref
@carp "unreferred cascadee" if @implicit and not o.ref.erred
return "#code#{input.terminator}\n#out" unless level
code += ", #out"
Expand Down
5 changes: 5 additions & 0 deletions test/operator.co
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ eq 1, n & n
eq 1, n&-n
eq 1, n & -n

funs =
2 |> -> &
3 |> -> &
eq 6, funs.0! * funs.1!

compileThrows 'stray reference' 2 '\n&'

compileThrows 'unreferred cascadee' 1 'a => b'
Expand Down

0 comments on commit 3a85ac1

Please sign in to comment.