Fix a bad indentation handling for if/try.
This commit is contained in:
parent
fe737255ba
commit
f97d8cd562
16
compiler.c
16
compiler.c
@ -1282,14 +1282,14 @@ static void ifStatement() {
|
||||
block(blockWidth,"else");
|
||||
endScope();
|
||||
}
|
||||
} else {
|
||||
if (!check(TOKEN_EOF) && !check(TOKEN_EOL)) {
|
||||
krk_ungetToken(parser.current);
|
||||
parser.current = parser.previous;
|
||||
if (blockWidth) {
|
||||
parser.previous = previous;
|
||||
}
|
||||
} else if (!check(TOKEN_EOF) && !check(TOKEN_EOL)) {
|
||||
krk_ungetToken(parser.current);
|
||||
parser.current = parser.previous;
|
||||
if (blockWidth) {
|
||||
parser.previous = previous;
|
||||
}
|
||||
} else {
|
||||
advance(); /* Ignore this blank indentation line */
|
||||
}
|
||||
}
|
||||
|
||||
@ -1519,6 +1519,8 @@ static void tryStatement() {
|
||||
if (blockWidth) {
|
||||
parser.previous = previous;
|
||||
}
|
||||
} else {
|
||||
advance(); /* Ignore this blank indentation line */
|
||||
}
|
||||
}
|
||||
|
||||
|
17
test/testWeirdIndentCase.krk
Normal file
17
test/testWeirdIndentCase.krk
Normal file
@ -0,0 +1,17 @@
|
||||
def test(val):
|
||||
if val:
|
||||
print("In if")
|
||||
# Comment
|
||||
# val -= int(val / max) * max
|
||||
return val
|
||||
|
||||
print("Result:", test(True))
|
||||
print("result:", test(False))
|
||||
|
||||
def test2(val):
|
||||
try:
|
||||
print("This has a comment on the next line.", val)
|
||||
# That could have been an else.
|
||||
return val
|
||||
|
||||
print("Result:", test2(True))
|
5
test/testWeirdIndentCase.krk.expect
Normal file
5
test/testWeirdIndentCase.krk.expect
Normal file
@ -0,0 +1,5 @@
|
||||
In if
|
||||
Result: True
|
||||
result: False
|
||||
This has a comment on the next line. True
|
||||
Result: True
|
Loading…
Reference in New Issue
Block a user