Skip to content

Commit d306d41

Browse files
committed
disallow juxtaposition with literals ending in .
part of #15731
1 parent acafa9b commit d306d41

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Breaking changes
8282
is now divided among the fields `code`, `slotnames`, `slottypes`, `slotflags`,
8383
`gensymtypes`, `rettype`, `nargs`, and `isva` in the `LambdaInfo` type ([#15609]).
8484

85+
* Juxtaposition of numeric literals ending in `.` (e.g. `1.x`) is no longer
86+
allowed ([#15731]).
87+
8588
Library improvements
8689
--------------------
8790

src/julia-parser.scm

+17-6
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@
323323
(string.sub s 1)
324324
s)
325325
r is-float32-literal)))
326+
(if (and (eqv? #\. (string.char s (string.dec s (length s))))
327+
(let ((nxt (peek-char port)))
328+
(or (identifier-start-char? nxt)
329+
(memv nxt '(#\( #\[ #\{ #\@ #\` #\~ #\")))))
330+
(error (string "invalid numeric constant \"" s (peek-char port) "\"")))
326331
;; n is #f for integers > typemax(UInt64)
327332
(cond (is-hex-float-literal (numchk n s) (double n))
328333
((eq? pred char-hex?) (fix-uint-neg neg (sized-uint-literal n s 4)))
@@ -815,27 +820,33 @@
815820
(- num)))
816821
num))
817822

818-
; given an expression and the next token, is there a juxtaposition
819-
; operator between them?
820-
(define (juxtapose? expr t)
823+
;; given an expression and the next token, is there a juxtaposition
824+
;; operator between them?
825+
(define (juxtapose? s expr t)
821826
(and (or (number? expr)
822827
(large-number? expr)
823828
(not (number? t)) ;; disallow "x.3" and "sqrt(2)2"
824829
;; to allow x'y as a special case
825830
#;(and (pair? expr) (memq (car expr) '(|'| |.'|))
826831
(not (memv t '(#\( #\[ #\{))))
827832
)
833+
(not (ts:space? s))
828834
(not (operator? t))
829835
(not (initial-reserved-word? t))
830836
(not (closing-token? t))
831837
(not (newline? t))
832-
(not (and (pair? expr) (syntactic-unary-op? (car expr))))))
838+
(not (and (pair? expr) (syntactic-unary-op? (car expr))))
839+
;; TODO: this would disallow juxtaposition with 0, which is ambiguous
840+
;; with e.g. hex literals `0x...`. however this is used for `0im`, which
841+
;; we might not want to break.
842+
#;(or (not (and (eq? expr 0)
843+
(symbol? t)))
844+
(error (string "invalid numeric constant \"" expr t "\"")))))
833845

834846
(define (parse-juxtapose ex s)
835847
(let ((next (peek-token s)))
836848
;; numeric literal juxtaposition is a unary operator
837-
(cond ((and (juxtapose? ex next)
838-
(not (ts:space? s)))
849+
(cond ((juxtapose? s ex next)
839850
(begin
840851
#;(if (and (number? ex) (= ex 0))
841852
(error "juxtaposition with literal \"0\""))

test/fft.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ m4 = [16. 2 3 13;
1111

1212
true_fft_m4 = [
1313
34. 34. 34. 34.;
14-
7. - 1.im -5. + 3.im -3. + 5.im 1. - 7.im;
14+
7. - 1.0im -5. + 3.0im -3. + 5.0im 1. - 7.0im;
1515
16. -16. -16. 16.;
16-
7. + 1.im -5. - 3.im -3. - 5.im 1. + 7.im ]
16+
7. + 1.0im -5. - 3.0im -3. - 5.0im 1. + 7.0im ]
1717

1818
true_fftn_m4 = [
1919
136. 0 0 0 ;

test/linalg/dense.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ end
311311
## Issue related tests
312312
# issue #1447
313313
let
314-
A = [1.+0.im 0; 0 1]
314+
A = [1.+0.0im 0; 0 1]
315315
B = pinv(A)
316316
for i = 1:4
317317
@test_approx_eq A[i] B[i]

test/sparsedir/sparsevector.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ let x = spv_x1, x2 = spv_x2
547547
@test exact_equal(complex(x, x),
548548
SparseVector(8, [2,5,6], [1.25+1.25im, -0.75-0.75im, 3.5+3.5im]))
549549
@test exact_equal(complex(x, x2),
550-
SparseVector(8, [1,2,5,6,7], [3.25im, 1.25+4.0im, -0.75+0.im, 3.5-5.5im, -6.0im]))
550+
SparseVector(8, [1,2,5,6,7], [3.25im, 1.25+4.0im, -0.75+0.0im, 3.5-5.5im, -6.0im]))
551551
@test exact_equal(complex(x2, x),
552-
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]))
552+
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]))
553553

554554
# real & imag
555555

0 commit comments

Comments
 (0)