Skip to content

Commit d46ae35

Browse files
committed
fix #16356, deprecate juxtaposing hex literals
1 parent a945af3 commit d46ae35

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Language changes
1919
* In string and character literals, backslash `\` may no longer
2020
precede unrecognized escape characters ([#22800]).
2121

22+
* Juxtaposing hex literals is deprecated, since it can lead to confusing
23+
code such as `0xapi == 0xa * pi` ([#16356]).
24+
2225
* Declaring arguments as `x::ANY` to avoid specialization has been replaced
2326
by `@nospecialize x`. ([#22666]).
2427

src/julia-parser.scm

+13-6
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,20 @@
337337
(write-char (read-char port) str)
338338
(read-digs #t #f)
339339
(disallow-dot))
340-
(io.ungetc port c))))
340+
(io.ungetc port c)))))
341+
(if (and (char? c)
342+
(or (and (or (eq? pred char-bin?) (eq? pred char-oct?))
343+
(char-numeric? c))
344+
(and (eq? pred char-hex?) (not is-hex-float-literal)
345+
(identifier-start-char? c)
346+
(syntax-deprecation port ;; remove after v0.7
347+
(string (get-output-string str) c)
348+
(string (get-output-string str) " * " c))
349+
#f))) ;; remove after v0.7
341350
;; disallow digits after binary or octal literals, e.g., 0b12
342-
(if (and (or (eq? pred char-bin?) (eq? pred char-oct?))
343-
(not (eof-object? c))
344-
(char-numeric? c))
345-
(error (string "invalid numeric constant \""
346-
(get-output-string str) c "\"")))))
351+
;; and disallow identifier chars after hex literals.
352+
(error (string "invalid numeric constant \""
353+
(get-output-string str) c "\""))))
347354
(let* ((s (get-output-string str))
348355
(r (cond ((eq? pred char-hex?) 16)
349356
((eq? pred char-oct?) 8)

0 commit comments

Comments
 (0)