julia
julia copied to clipboard
Strange parser error message for `"x".3`
The expression "x".3
gives the following error message in the REPL:
julia> "x".3
ERROR: cannot document the following expression:
0.3
This is strange because 0.3
is not the original expression and inconsistent compared to the error for "x".y
which is more readable:
julia> "x".y
ERROR: type String has no field y
Could this be updated to be more consistent between the two errors?
Versioninfo:
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 × AMD Ryzen 7 PRO 4750U with Radeon Graphics
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
Threads: 1 on 16 virtual cores
This is because .3
is a floating-point literal, with same value as 0.3
. So the error message actually makes considerable sense.
This could be a parser error, which would be more understandable. I don't see any advantage of allowing a string and a literal value right next to each other. Anything that I can come up with that can be documented is not allowed directly after a string literal.
Perhaps the parser could emit this error instead?
julia> "test"a
ERROR: ParseError:
# Error @ REPL[22]:1:7
"test"a
# └ ── cannot juxtapose string literal
getproperty
is called if the numeric literal is prefixed by :
:
julia> "x".:.3
ERROR: MethodError: no method matching getproperty(::String, ::Float64)