julia icon indicating copy to clipboard operation
julia copied to clipboard

Strange parser error message for `"x".3`

Open llbit opened this issue 1 year ago • 4 comments

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

llbit avatar Feb 14 '24 10:02 llbit

This is because .3 is a floating-point literal, with same value as 0.3. So the error message actually makes considerable sense.

nsajko avatar Feb 14 '24 12:02 nsajko

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.

jakobnissen avatar Feb 14 '24 12:02 jakobnissen

Perhaps the parser could emit this error instead?

julia> "test"a
ERROR: ParseError:
# Error @ REPL[22]:1:7
"test"a
#     └ ── cannot juxtapose string literal

BioTurboNick avatar Feb 14 '24 17:02 BioTurboNick

getproperty is called if the numeric literal is prefixed by ::

julia> "x".:.3
ERROR: MethodError: no method matching getproperty(::String, ::Float64)

uniment avatar Feb 15 '24 16:02 uniment