Skip to content

Commit

Permalink
fix #16356, deprecate juxtaposing bin, oct, and hex literals
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 18, 2017
1 parent 5fd053f commit e3eacbb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Language changes
* In string and character literals, backslash `\` may no longer
precede unrecognized escape characters ([#22800]).

* Juxtaposing hex literals is deprecated, since it can lead to confusing
code such as `0xapi == 0xa * pi` ([#16356]).

* Declaring arguments as `x::ANY` to avoid specialization has been replaced
by `@nospecialize x`. ([#22666]).

Expand Down
19 changes: 13 additions & 6 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,20 @@
(write-char (read-char port) str)
(read-digs #t #f)
(disallow-dot))
(io.ungetc port c))))
(io.ungetc port c)))))
(if (and (char? c)
(or (eq? pred char-bin?) (eq? pred char-oct?)
(and (eq? pred char-hex?) (not is-hex-float-literal)))
(or (char-numeric? c)
(and (identifier-start-char? c)
(syntax-deprecation port ;; remove after v0.7
(string (get-output-string str) c)
(string (get-output-string str) " * " c))
#f))) ;; remove after v0.7
;; disallow digits after binary or octal literals, e.g., 0b12
(if (and (or (eq? pred char-bin?) (eq? pred char-oct?))
(not (eof-object? c))
(char-numeric? c))
(error (string "invalid numeric constant \""
(get-output-string str) c "\"")))))
;; and disallow identifier chars after hex literals.
(error (string "invalid numeric constant \""
(get-output-string str) c "\""))))
(let* ((s (get-output-string str))
(r (cond ((eq? pred char-hex?) 16)
((eq? pred char-oct?) 8)
Expand Down
8 changes: 4 additions & 4 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,8 @@ timesofar("unary arithmetic")
@check_bit_operation broadcast(^, 1.0im, b2) Matrix{Complex128}
@check_bit_operation broadcast(^, 0im, b2) Matrix{Complex{Int}}
@check_bit_operation broadcast(^, 1im, b2) Matrix{Complex{Int}}
@check_bit_operation broadcast(^, 0x0im, b2) Matrix{Complex{UInt8}}
@check_bit_operation broadcast(^, 0x1im, b2) Matrix{Complex{UInt8}}
@check_bit_operation broadcast(^, 0x0*im, b2) Matrix{Complex{UInt8}}
@check_bit_operation broadcast(^, 0x1*im, b2) Matrix{Complex{UInt8}}
end

@testset "Matrix/Number" begin
Expand Down Expand Up @@ -982,7 +982,7 @@ timesofar("unary arithmetic")
@check_bit_operation broadcast(^, b1, 0.0) Matrix{Float64}
@check_bit_operation broadcast(^, b1, 1.0) Matrix{Float64}
@check_bit_operation broadcast(^, b1, 0.0im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 0x0im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 0x0*im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 0im) Matrix{Complex128}
@test_throws DomainError broadcast(^, b1, -1)

Expand All @@ -991,7 +991,7 @@ timesofar("unary arithmetic")
@check_bit_operation broadcast(^, b1, 1.0im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, -1im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 1im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 0x1im) Matrix{Complex128}
@check_bit_operation broadcast(^, b1, 0x1*im) Matrix{Complex128}
end
end

Expand Down

0 comments on commit e3eacbb

Please sign in to comment.