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

Crystal REPL instantly executes statement with intertwined heredoc #14597

Open
BlobCodes opened this issue May 15, 2024 · 1 comment
Open

Crystal REPL instantly executes statement with intertwined heredoc #14597

BlobCodes opened this issue May 15, 2024 · 1 comment

Comments

@BlobCodes
Copy link
Contributor

BlobCodes commented May 15, 2024

Bug Report

The interpreter instantly executes statements with intertwined heredocs, even though it hasn't been terminated yet.
The heredoc is simply never read.

Example:

icr:1> p <<-EOF.to_i
Unhandled exception: Invalid Int32: "" (ArgumentError)

$ bin/crystal --version
Using compiled compiler at .build/crystal
Crystal 1.13.0-dev [a23f0fbee] (2024-05-07)

LLVM: 18.1.1
Default target: x86_64-redhat-linux-gnu
@I3oris
Copy link
Contributor

I3oris commented May 15, 2024

The workaround is to press alt-enter to force continue on a new line.

This error happen because the reader doesn't know if it should wait for a new line or not before sending to the interpreter.

The current method used is to parse it anyway and if it raises an unterminated error, it lets the user types a new line.
See code here

However in this case the parser raise 'invalid int32' which tell no information about if the expression is complete or not.

The solution is either to raises an unterminated heredoc error in this case, either we could add a flag on the parser that said if the incorect parsed expression is just 'unterminated' and could be continued on a new line.
(This mean to correctly set the flag when the parser raises an error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants