Skip to content

Commit

Permalink
Merge pull request #15813 from JuliaLang/jb/fix15763
Browse files Browse the repository at this point in the history
fix #15763, disallow newline immediately after `if`
  • Loading branch information
JeffBezanson committed Apr 10, 2016
2 parents 4eced1a + 3ecc2d4 commit 9ee9aef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Language changes
* Simple 2-argument comparisons like `A < B` are parsed as calls intead of using the
`:comparison` expression type.

* The `if` keyword cannot be followed immediately by a line break ([#15763]).

Command-line option changes
---------------------------

Expand Down Expand Up @@ -184,3 +186,4 @@ Deprecated or removed
[#15258]: https://github.com/JuliaLang/julia/issues/15258
[#15550]: https://github.com/JuliaLang/julia/issues/15550
[#15609]: https://github.com/JuliaLang/julia/issues/15609
[#15763]: https://github.com/JuliaLang/julia/issues/15763
4 changes: 4 additions & 0 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,10 @@
,body)))

((if)
(if (newline? (peek-token s))
(syntax-deprecation s "if with line break before condition" "")
#;(error (string "missing condition in \"if\" at " current-filename
":" (- (input-port-line (ts:port s)) 1))))
(let* ((test (parse-cond s))
(then (if (memq (require-token s) '(else elseif))
'(block)
Expand Down
5 changes: 5 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,8 @@ test_parseerror("0x1.0p", "invalid numeric constant \"0x1.0\"")
@test expand(Base.parse_input_line("""
try = "No"
""")) == Expr(:error, "unexpected \"=\"")

# issue #15763
# TODO enable post-0.5
#test_parseerror("if\nfalse\nend", "missing condition in \"if\" at none:1")
test_parseerror("if false\nelseif\nend", "missing condition in \"elseif\" at none:2")

0 comments on commit 9ee9aef

Please sign in to comment.