diff --git a/src/parser.jl b/src/parser.jl index 385c0da2..1ffb499e 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -3180,11 +3180,16 @@ function parse_string(ps::ParseState, raw::Bool) # "a $(x + y) b" ==> (string "a " (parens (call-i x + y)) " b") # "hi$("ho")" ==> (string "hi" (parens (string "ho"))) m = position(ps) - parse_atom(ps) - if peek_behind(ps, skip_parens=false).kind != K"parens" - # "$(x,y)" ==> (string (error (tuple-p x y))) + bump(ps, TRIVIA_FLAG) + opts = parse_brackets(ps, K")") do had_commas, had_splat, num_semis, num_subexprs + return (needs_parameters=false, + simple_interp=!had_commas && !had_splat && num_semis == 0) + end + if !opts.simple_interp || peek_behind(ps).kind == K"generator" + # "$(x,y)" ==> (string (parens (error x y))) emit(ps, m, K"error", error="invalid interpolation syntax") end + emit(ps, m, K"parens") elseif k == K"var" # var identifiers disabled in strings # "$var" ==> (string var) diff --git a/test/diagnostics.jl b/test/diagnostics.jl index 87180d0d..9bba7bb3 100644 --- a/test/diagnostics.jl +++ b/test/diagnostics.jl @@ -96,6 +96,9 @@ end Diagnostic(2, 19, :error, "try without catch or finally") Diagnostic(20, 19, :error, "Expected `end`") ] + + @test diagnostic("\"\$(x,y)\"") == + Diagnostic(3, 7, :error, "invalid interpolation syntax") end @testset "parser warnings" begin diff --git a/test/parser.jl b/test/parser.jl index a1e71ce4..f35d8957 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -869,8 +869,9 @@ tests = [ "\"\"\"\n\$x\n a\"\"\"" => "(string-s x \"\\n\" \" a\")" "\"a \$(x + y) b\"" => "(string \"a \" (parens (call-i x + y)) \" b\")" "\"hi\$(\"ho\")\"" => "(string \"hi\" (parens (string \"ho\")))" - "\"\$(x,y)\"" => "(string (error (tuple-p x y)))" - "\"\$(x;y)\"" => "(string (error (block-p x y)))" + "\"\$(x,y)\"" => "(string (parens (error x y)))" + "\"\$(x;y)\"" => "(string (parens (error x y)))" + "\"\$(x for y in z)\"" => "(string (parens (error (generator x (= y z)))))" "\"a \$foo b\"" => "(string \"a \" foo \" b\")" "\"\$var\"" => "(string var)" "\"\$outer\"" => "(string outer)"