From 149f771ff74cfed8fce8f6d01508fc5d584f7ede Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 21 Apr 2018 15:13:34 -0400 Subject: [PATCH] fix some cases of dot syntax lowering fix #26739, error for `sum.[1]` fix #26873, should have no error for `f."a"` --- src/julia-syntax.scm | 4 ++-- src/toplevel.c | 5 ++--- test/syntax.jl | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index ad7b4692c36da..d911737cb088c 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1738,12 +1738,12 @@ `(fuse ,(to-lambda f args kws) ,args_)))) (if (and (pair? e) (eq? (car e) '|.|)) (let ((f (cadr e)) (x (caddr e))) - (cond ((or (eq? (car x) 'quote) (eq? (car x) 'inert) (eq? (car x) '$)) + (cond ((or (atom? x) (eq? (car x) 'quote) (eq? (car x) 'inert) (eq? (car x) '$)) `(call (top getproperty) ,f ,x)) ((eq? (car x) 'tuple) (make-fuse f (cdr x))) (else - (error (string "invalid syntax " (deparse e)))))) + (error (string "invalid syntax \"" (deparse e) "\""))))) (if (and (pair? e) (eq? (car e) 'call) (dotop? (cadr e))) (make-fuse (undotop (cadr e)) (cddr e)) e))) diff --git a/src/toplevel.c b/src/toplevel.c index ea3e26992234e..427fb79144ead 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -641,9 +641,8 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e jl_error("syntax: malformed \".\" expression"); jl_value_t *lhs = jl_exprarg(ex, 0); jl_value_t *rhs = jl_exprarg(ex, 1); - // ('.' f (tuple args...)) is a broadcast instead, which doesn't - // go through this fast path. - if (!jl_is_expr(rhs) || ((jl_expr_t*)rhs)->head != tuple_sym) + // only handle `a.b` syntax here + if (jl_is_quotenode(rhs) && jl_is_symbol(jl_fieldref(rhs,0))) return jl_eval_dot_expr(m, lhs, rhs, fast); } if (ptls->in_pure_callback) { diff --git a/test/syntax.jl b/test/syntax.jl index 9f9f0d9687dde..4a1a64a8cc1d1 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -939,8 +939,8 @@ g21054(>:) = >:2 @test g21054(-) == -2 # issue #21168 -@test Meta.lower(Main, :(a.[1])) == Expr(:error, "invalid syntax a.[1]") -@test Meta.lower(Main, :(a.{1})) == Expr(:error, "invalid syntax a.{1}") +@test Meta.lower(Main, :(a.[1])) == Expr(:error, "invalid syntax \"a.[1]\"") +@test Meta.lower(Main, :(a.{1})) == Expr(:error, "invalid syntax \"a.{1}\"") # Issue #21225 let abstr = Meta.parse("abstract type X end") @@ -1406,3 +1406,16 @@ invalid assignment location "function (s, o...) end end\"""" end + +# issue #26739 +@test_throws ErrorException("syntax: invalid syntax \"sin.[1]\"") eval(@__MODULE__, :(sin.[1])) + +# issue #26873 +f26873 = 0 +try + include_string(@__MODULE__, """f26873."a" """) + @test false +catch e + @test e isa LoadError + @test e.error isa MethodError +end