Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous parsing of x!==nothing #439

Open
StevenWhitaker opened this issue Jun 14, 2024 · 2 comments
Open

Ambiguous parsing of x!==nothing #439

StevenWhitaker opened this issue Jun 14, 2024 · 2 comments
Labels
breaking syntax change syntax wat Syntax problem in the reference parser we may consider fixing

Comments

@StevenWhitaker
Copy link

The following demonstrates a parser ambiguity that I think should throw a ParseError similar to how 1.+1 throws an error:

julia> x! = y -> y[1] = 1
#1 (generic function with 1 method)

julia> x! == nothing
false

julia> x!==nothing
ERROR: UndefVarError: `x` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[4]:1

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × 13th Gen Intel(R) Core(TM) i9-13900HX
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, goldmont)
Threads: 32 default, 0 interactive, 16 GC (on 32 virtual cores)
Environment:
  JULIA_NUM_THREADS = 32
  JULIA_PKG_USE_CLI_GIT = true

In particular, does x!==nothing mean x! == nothing or x !== nothing? The parser silently assumes the latter. I personally always include whitespace, thus circumventing the issue, but I ran across a line of code in NonlinearSolve.jl that does not have whitespace, and so I was surprised the syntax was allowed!

@nsajko nsajko added syntax wat Syntax problem in the reference parser we may consider fixing syntax change breaking labels Jun 14, 2024
@nsajko
Copy link

nsajko commented Jun 14, 2024

xref JuliaLang/julia#46411

@c42f
Copy link
Member

c42f commented Jul 21, 2024

Yes, the tokenizer assumes != should always be parsed as a token if it's present, taking precedence over a ! on the end of an identifier.

I'm not sure x!=1 should be an error (and it would be breaking to make it one - probably relatively high on the breaking things scale if I had to guess).

I personally agree it's not great style, but I'm not even sure this should be a warning - I'm somewhat inclined to say this belongs in a linter (and code formatting tools) rather than in the parser itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking syntax change syntax wat Syntax problem in the reference parser we may consider fixing
Projects
None yet
Development

No branches or pull requests

3 participants