disallow inline chained call after func glyph (#4590)

This commit is contained in:
Julian Rosse 2017-06-29 21:00:01 -05:00 committed by Geoffrey Booth
parent b1d2061cbc
commit 58c608620e
3 changed files with 13 additions and 3 deletions

View File

@ -441,7 +441,7 @@
return this.tokens.splice((this.tag(i - 1) === ',' ? i - 1 : i), 0, outdent);
};
return this.scanTokens(function(token, i, tokens) {
var j, k, ref, ref1, ref2, tag;
var j, k, ref, ref1, tag;
[tag] = token;
if (tag === 'TERMINATOR') {
if (this.tag(i + 1) === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
@ -462,7 +462,7 @@
return 2 + j;
}
}
if ((tag === '->' || tag === '=>') && ((ref2 = this.tag(i + 1)) === ',' || ref2 === '.')) {
if ((tag === '->' || tag === '=>') && (this.tag(i + 1) === ',' || this.tag(i + 1) === '.' && token.newLine)) {
[indent, outdent] = this.indentation(tokens[i]);
tokens.splice(i + 1, 0, indent, outdent);
return 1;

View File

@ -434,7 +434,7 @@ exports.Rewriter = class Rewriter
for j in [1..2] when @tag(i + j) in ['OUTDENT', 'TERMINATOR', 'FINALLY']
tokens.splice i + j, 0, @indentation()...
return 2 + j
if tag in ['->', '=>'] and @tag(i + 1) in [',', '.']
if tag in ['->', '=>'] and (@tag(i + 1) is ',' or @tag(i + 1) is '.' and token.newLine)
[indent, outdent] = @indentation tokens[i]
tokens.splice i + 1, 0, indent, outdent
return 1

View File

@ -1601,6 +1601,16 @@ test 'Bound method called as callback before binding throws runtime error', ->
ok no
d = new Derived
test "#3845/#3446: chain after function glyph (but not inline)", ->
assertErrorFormat '''
a -> .b
''',
'''
[stdin]:1:6: error: unexpected .
a -> .b
^
'''
test "#3906: error for unusual indentation", ->
assertErrorFormat '''
a