diff --git a/src/ast.scm b/src/ast.scm index e3183cbe31dfd..4c0ae0d0dda70 100644 --- a/src/ast.scm +++ b/src/ast.scm @@ -5,6 +5,16 @@ (define (deparse-arglist l (sep ",")) (string.join (map deparse l) sep)) (define (deparse e) + (define (block-stmts e) + (if (and (pair? e) (eq? (car e) 'block)) + (cdr e) + (list e))) + (define (deparse-block head lst) + (string head "\n" + (string.join (map (lambda (ex) (string " " (deparse ex))) + lst) + "\n") + "\nend")) (cond ((or (symbol? e) (number? e)) (string e)) ((string? e) (print-to-string e)) ((eq? e #t) "true") @@ -67,17 +77,16 @@ (string "# line " (cadr e)) (string "# " (caddr e) ", line " (cadr e)))) ((block) - (string "begin\n" - (string.join (map (lambda (ex) (string " " (deparse ex))) - (cdr e)) - "\n") - "\nend")) + (deparse-block "begin" (cdr e))) ((comprehension) (string "[ " (deparse (cadr e)) " for " (deparse-arglist (cddr e) ", ") " ]")) ((generator) (string "(" (deparse (cadr e)) " for " (deparse-arglist (cddr e) ", ") ")")) ((where) (string (deparse (cadr e)) " where " (deparse (caddr e)))) + ((function for while) + (deparse-block (string (car e) " " (deparse (cadr e))) + (block-stmts (caddr e)))) (else (string e)))))) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 0e517506e09e7..d6a81d8aa014c 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -954,7 +954,7 @@ (where (if (and (pair? name) (eq? (car name) 'where)) (let ((w (flatten-where-expr name))) (begin0 (cddr w) - (if (not (and (pair? (cadr w)) (eq? (caadr w) 'call))) + (if (not (and (pair? (cadr w)) (memq (caadr w) '(call |::|)))) (error (string "invalid assignment location \"" (deparse name) "\""))) (set! name (cadr w)))) #f)) @@ -1000,7 +1000,8 @@ #f name))) (expand-forms (method-def-expr name sparams argl (caddr e) isstaged rett)))) - (else e)))) + (else + (error (string "invalid assignment location \"" (deparse name) "\"")))))) ;; handle ( )->( ) function expressions. blocks `(a;b=1)` on the left need to be ;; converted to argument lists with kwargs. @@ -3553,7 +3554,7 @@ f(x) = yt(x) ((...) (error "\"...\" expression outside call")) (else - (error (string "unhandled expr " e)))))) + (error (string "invalid syntax " (deparse e))))))) ;; introduce new slots for assigned arguments (for-each (lambda (v) (if (vinfo:asgn v) diff --git a/test/core.jl b/test/core.jl index 404ec926b6288..722f6d9f9bf01 100644 --- a/test/core.jl +++ b/test/core.jl @@ -4179,6 +4179,13 @@ function f17613_2(x)::Float64 end @test isa(f17613_2(1), Float64) +# return type decl with `where` +function where1090(x::Array{T})::T where T<:Real + return x[1] + 2.0 +end +@test where1090([4]) === 6 +@test_throws MethodError where1090(String[]) + type A1090 end Base.convert(::Type{Int}, ::A1090) = "hey" f1090()::Int = A1090()