Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow juxtaposition with literals ending in . #16339

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Breaking changes
is now divided among the fields `code`, `slotnames`, `slottypes`, `slotflags`,
`gensymtypes`, `rettype`, `nargs`, and `isva` in the `LambdaInfo` type ([#15609]).

* Juxtaposition of numeric literals ending in `.` (e.g. `1.x`) is no longer
allowed ([#15731]).

Library improvements
--------------------

Expand Down
23 changes: 17 additions & 6 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@
(string.sub s 1)
s)
r is-float32-literal)))
(if (and (eqv? #\. (string.char s (string.dec s (length s))))
(let ((nxt (peek-char port)))
(or (identifier-start-char? nxt)
(memv nxt '(#\( #\[ #\{ #\@ #\` #\~ #\")))))
(error (string "invalid numeric constant \"" s (peek-char port) "\"")))
;; n is #f for integers > typemax(UInt64)
(cond (is-hex-float-literal (numchk n s) (double n))
((eq? pred char-hex?) (fix-uint-neg neg (sized-uint-literal n s 4)))
Expand Down Expand Up @@ -815,27 +820,33 @@
(- num)))
num))

; given an expression and the next token, is there a juxtaposition
; operator between them?
(define (juxtapose? expr t)
;; given an expression and the next token, is there a juxtaposition
;; operator between them?
(define (juxtapose? s expr t)
(and (or (number? expr)
(large-number? expr)
(not (number? t)) ;; disallow "x.3" and "sqrt(2)2"
;; to allow x'y as a special case
#;(and (pair? expr) (memq (car expr) '(|'| |.'|))
(not (memv t '(#\( #\[ #\{))))
)
(not (ts:space? s))
(not (operator? t))
(not (initial-reserved-word? t))
(not (closing-token? t))
(not (newline? t))
(not (and (pair? expr) (syntactic-unary-op? (car expr))))))
(not (and (pair? expr) (syntactic-unary-op? (car expr))))
;; TODO: this would disallow juxtaposition with 0, which is ambiguous
;; with e.g. hex literals `0x...`. however this is used for `0im`, which
;; we might not want to break.
#;(or (not (and (eq? expr 0)
(symbol? t)))
(error (string "invalid numeric constant \"" expr t "\"")))))

(define (parse-juxtapose ex s)
(let ((next (peek-token s)))
;; numeric literal juxtaposition is a unary operator
(cond ((and (juxtapose? ex next)
(not (ts:space? s)))
(cond ((juxtapose? s ex next)
(begin
#;(if (and (number? ex) (= ex 0))
(error "juxtaposition with literal \"0\""))
Expand Down
4 changes: 2 additions & 2 deletions test/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ m4 = [16. 2 3 13;

true_fft_m4 = [
34. 34. 34. 34.;
7. - 1.im -5. + 3.im -3. + 5.im 1. - 7.im;
7. - 1.0im -5. + 3.0im -3. + 5.0im 1. - 7.0im;
16. -16. -16. 16.;
7. + 1.im -5. - 3.im -3. - 5.im 1. + 7.im ]
7. + 1.0im -5. - 3.0im -3. - 5.0im 1. + 7.0im ]

true_fftn_m4 = [
136. 0 0 0 ;
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ end
## Issue related tests
# issue #1447
let
A = [1.+0.im 0; 0 1]
A = [1.+0.0im 0; 0 1]
B = pinv(A)
for i = 1:4
@test_approx_eq A[i] B[i]
Expand Down
4 changes: 2 additions & 2 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ let x = spv_x1, x2 = spv_x2
@test exact_equal(complex(x, x),
SparseVector(8, [2,5,6], [1.25+1.25im, -0.75-0.75im, 3.5+3.5im]))
@test exact_equal(complex(x, x2),
SparseVector(8, [1,2,5,6,7], [3.25im, 1.25+4.0im, -0.75+0.im, 3.5-5.5im, -6.0im]))
SparseVector(8, [1,2,5,6,7], [3.25im, 1.25+4.0im, -0.75+0.0im, 3.5-5.5im, -6.0im]))
@test exact_equal(complex(x2, x),
SparseVector(8, [1,2,5,6,7], [3.25+0.im, 4.0+1.25im, -0.75im, -5.5+3.5im, -6.0+0.im]))
SparseVector(8, [1,2,5,6,7], [3.25+0.0im, 4.0+1.25im, -0.75im, -5.5+3.5im, -6.0+0.0im]))

# real & imag

Expand Down