Skip to content

Commit 3ecc2d4

Browse files
committed
fix #15763, deprecate newline immediately after if
1 parent b76bc89 commit 3ecc2d4

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Language changes
3838
* Simple 2-argument comparisons like `A < B` are parsed as calls intead of using the
3939
`:comparison` expression type.
4040

41+
* The `if` keyword cannot be followed immediately by a line break ([#15763]).
42+
4143
Command-line option changes
4244
---------------------------
4345

@@ -181,3 +183,4 @@ Deprecated or removed
181183
[#15258]: https://github.com/JuliaLang/julia/issues/15258
182184
[#15550]: https://github.com/JuliaLang/julia/issues/15550
183185
[#15609]: https://github.com/JuliaLang/julia/issues/15609
186+
[#15763]: https://github.com/JuliaLang/julia/issues/15763

src/julia-parser.scm

+4
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@
10941094
,body)))
10951095

10961096
((if)
1097+
(if (newline? (peek-token s))
1098+
(syntax-deprecation s "if with line break before condition" "")
1099+
#;(error (string "missing condition in \"if\" at " current-filename
1100+
":" (- (input-port-line (ts:port s)) 1))))
10971101
(let* ((test (parse-cond s))
10981102
(then (if (memq (require-token s) '(else elseif))
10991103
'(block)

test/parse.jl

+5
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,8 @@ test_parseerror("0x1.0p", "invalid numeric constant \"0x1.0\"")
401401
@test expand(Base.parse_input_line("""
402402
try = "No"
403403
""")) == Expr(:error, "unexpected \"=\"")
404+
405+
# issue #15763
406+
# TODO enable post-0.5
407+
#test_parseerror("if\nfalse\nend", "missing condition in \"if\" at none:1")
408+
test_parseerror("if false\nelseif\nend", "missing condition in \"elseif\" at none:2")

0 commit comments

Comments
 (0)