Skip to content

Commit

Permalink
add error for duplicate names in a named tuple expression
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jun 2, 2017
1 parent 8a653bd commit b19f3e7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2163,11 +2163,14 @@
(if (not (every (lambda (x) (and (assignment? x) (symbol? (cadr x))))
(cdr e)))
(error (string "invalid named tuple syntax \"" (deparse e) "\""))
(expand-forms `(call (top namedtuple)
(curly (core NamedTuple)
(tuple ,@(map (lambda (x) (quotify (cadr x)))
(cdr e))))
,@(map caddr (cdr e)))))
(let* ((names (map cadr (cdr e)))
(dups (has-dups names)))
(if dups
(error (string "field name \"" (car dups) "\" repeated in named tuple"))
(expand-forms `(call (top namedtuple)
(curly (core NamedTuple)
(tuple ,@(map quotify names)))
,@(map caddr (cdr e)))))))
(expand-forms `(call (core tuple) ,@(cdr e)))))

'=>
Expand Down

0 comments on commit b19f3e7

Please sign in to comment.