Skip to content

Commit

Permalink
fix some cases of dot syntax lowering
Browse files Browse the repository at this point in the history
fix #26739, error for `sum.[1]`
fix #26873, should have no error for `f."a"`
  • Loading branch information
JeffBezanson committed Apr 21, 2018
1 parent 1c5ed70 commit 149f771
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 2 additions & 3 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 15 additions & 2 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 149f771

Please sign in to comment.