REPL-only: Print a hint if the user types exit in the REPL using an AST transform #42011
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #38522
This is an updated version of #38522 (and also succeeds #21362, #38307), that uses a REPL backend Abstract Syntax Tree transform in order to implement the hint if the user just types
exit
.One advantage of using an AST transform is that the hint and its small overhead can be removed if desired. Another is that the line string entered does not need to be parsed again.
The hint is conscious of if
Main.exit
has been redefined. It will not print the hint in that case.An implementation note is that this does not use
Base.isbindingresolved(Main, :exit) && isdefined(Main, :exit)
per #38522 (comment). Compilingisdefined(Main, :exit)
will result in the:exit
binding being resolved inMain
, which defeats the purpose. It is also insufficient since what we really want to know is ifMain.exit
isBase.exit
. Therefore, theif Main.exit === Base.exit
statement is returned as part of the AST transform. This allowsMain.exit
to be redefined as above while checking ifexit
is what we expect it to be.This pull request has been rebased on afc504b.
To handle the situation where the user types
quit
orquit()
see #41990.