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

When single line comment is the last line in file the run fails #221

Closed
croraf opened this issue Jan 14, 2020 · 11 comments · Fixed by #228
Closed

When single line comment is the last line in file the run fails #221

croraf opened this issue Jan 14, 2020 · 11 comments · Fixed by #228

Comments

@croraf
Copy link
Contributor

croraf commented Jan 14, 2020

For example this fails

var a = 7;
console.log(5);

//console.log(6);

While these work:

var a = 7;
console.log(5);

console.log(6);
var a = 7;
console.log(5);
// something

OS: Ubuntu 19.10, uname 5.3.0-26-generic

@IovoslavIovchev
Copy link
Contributor

Can you give more details on the error. I am currently unable to reproduce this on master (currently e38ac20)

@croraf
Copy link
Contributor Author

croraf commented Jan 14, 2020

I checked out master yesterday (same commit as yours).

boa$ cargo run -- test.js
   Compiling Boa v0.5.1 (/home/croraf/Desktop/Programiranje/learning-rust/boa)
    Finished dev [unoptimized + debuginfo] target(s) in 3.11s
     Running `target/debug/boa test.js`
thread 'main' panicked at 'lexing failed: LexerError { details: "finished" }', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'main' panicked at 'lexing failed: LexerError { details: "finished" }', src/libcore/result.rs:1165:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:76
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:60
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:64
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:196
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:210
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:473
  11: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:380
  12: rust_begin_unwind
             at src/libstd/panicking.rs:307
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::result::unwrap_failed
             at src/libcore/result.rs:1165
  15: core::result::Result<T,E>::expect
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/result.rs:960
  16: boa::parser_expr
             at src/lib/lib.rs:52
  17: boa::forward
             at src/lib/lib.rs:61
  18: boa::exec
             at src/lib/lib.rs:84
  19: boa::main
             at src/bin/bin.rs:57
  20: std::rt::lang_start::{{closure}}
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  21: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:49
  22: std::panicking::try::do_call
             at src/libstd/panicking.rs:292
  23: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:80
  24: std::panicking::try
             at src/libstd/panicking.rs:271
  25: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  26: std::rt::lang_start_internal
             at src/libstd/rt.rs:48
  27: std::rt::lang_start
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  28: main
  29: __libc_start_main
  30: _start

@IovoslavIovchev
Copy link
Contributor

@croraf Which version of cargo are you on? Are you using nightly?

@croraf
Copy link
Contributor Author

croraf commented Jan 16, 2020

cargo 1.39.0 (1c6ec66d5 2019-09-30)

@IovoslavIovchev
Copy link
Contributor

Is this still happening on the latest master?

@croraf
Copy link
Contributor Author

croraf commented Jan 17, 2020

Yes. It is still happening with the same error. f134a07

@IovoslavIovchev
Copy link
Contributor

@croraf would you like to look into it?

@jasonwilliams
Copy link
Member

jasonwilliams commented Jan 18, 2020

var a = 7;
console.log(5);

//console.log(6);

Does not fail for me.

    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target\debug\boa.exe`
5
[src/bin/bin.rs:57] exec(&buffer) = "undefined"

rustc 1.40.0 (73528e339 2019-12-16)
cargo 1.40.0 (bc8e4c8be 2019-11-22)
commit: f134a07

@jasonwilliams
Copy link
Member

jasonwilliams commented Jan 18, 2020

@croraf did you run cargo clean?
could you set RUST_BACKTRACE=1 or RUST_BACKTRACE=full and run it again if it keeps failing then post the full stack trace

@croraf
Copy link
Contributor Author

croraf commented Jan 19, 2020

@jasonwilliams I ran cargo clean now and fails with the same error. The stacktrace looks like the one already posted.

boa$ RUST_BACKTRACE=1 cargo run -- test.js
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/boa test.js`
thread 'main' panicked at 'lexing failed: LexerError { details: "finished" }', src/libcore/result.rs:1165:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:76
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:60
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:64
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:196
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:210
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:473
  11: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:380
  12: rust_begin_unwind
             at src/libstd/panicking.rs:307
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::result::unwrap_failed
             at src/libcore/result.rs:1165
  15: core::result::Result<T,E>::expect
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/result.rs:960
  16: boa::parser_expr
             at src/lib/lib.rs:52
  17: boa::forward
             at src/lib/lib.rs:61
  18: boa::exec
             at src/lib/lib.rs:84
  19: boa::main
             at src/bin/bin.rs:57
  20: std::rt::lang_start::{{closure}}
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  21: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:49
  22: std::panicking::try::do_call
             at src/libstd/panicking.rs:292
  23: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:80
  24: std::panicking::try
             at src/libstd/panicking.rs:271
  25: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  26: std::rt::lang_start_internal
             at src/libstd/rt.rs:48
  27: std::rt::lang_start
             at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  28: main
  29: __libc_start_main
  30: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.```

@croraf
Copy link
Contributor Author

croraf commented Jan 19, 2020

OK, I checked the code and the bug is when lexing the "line comment" branch, which is the only thing calling the read_line method.

The read_line method is calling next in a loop without peaking first, finally throwing an error of the termination of the iteration, without closing the token.

Proposed solution in #228

Inspecting further it seems next should't return Result<> at all. It should either return char, or panic. The reason being the following: the next char should always be peaked at before trying to get it. If this does not happen it is a panic. I made that proposal in the separate PR.

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

Successfully merging a pull request may close this issue.

3 participants