Skip to content

Commit

Permalink
parser error for invalid : after imports (JuliaLang#34694)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored and ravibitsgoa committed Apr 6, 2020
1 parent 15d6937 commit 04e88a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1577,8 +1577,13 @@
(else #t)))
(rest (if done
'()
(parse-comma-separated s (lambda (s)
(parse-import s word))))))
(let ((ex (parse-comma-separated s (lambda (s)
(parse-import s word)))))
(if (eq? (peek-token s) ':)
(error (string "\":\" in \"" word "\" syntax can only be used "
"when importing a single module. "
"Split imports into multiple lines."))
ex)))))
(if from
`(,word (|:| ,first ,@rest))
(list* word first rest))))
Expand Down
18 changes: 18 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,21 @@ end
@test :(@foo{bar}[baz]) == :((@foo{bar})[baz])
@test :(@foo{bar} + baz) == :((@foo{bar}) + baz)
end

@testset "issue #34650" begin
for imprt in [:using, :import]
@test Meta.isexpr(Meta.parse("$imprt A, B"), imprt)
@test Meta.isexpr(Meta.parse("$imprt A: x, y, z"), imprt)

err = Expr(
:error,
"\":\" in \"$imprt\" syntax can only be used when importing a single module. " *
"Split imports into multiple lines."
)
ex = Meta.parse("$imprt A, B: x, y", raise=false)
@test ex == err

ex = Meta.parse("$imprt A: x, B: y", raise=false)
@test ex == err
end
end

0 comments on commit 04e88a1

Please sign in to comment.