asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

Parse errors when file ends in a comment sans newline #112

Open perimosocordiae opened 2 years ago

perimosocordiae commented 2 years ago

Two reproducers here, both importantly with no newline at the end of the file. (That is, the last character in the file is 'h'.)

Input 1:

// blah

Output:

*** SIGSEGV received at time=1649300950 on cpu 2 ***
PC: @          0x1053752  (unknown)  frontend::(anonymous namespace)::ConsumeWhile<>()
    @          0x15023c0         64  absl::WriteFailureInfo()
    @          0x15020a4        224  absl::AbslFailureSignalHandler()
    @     0x7f88c47ef520  (unknown)  (unknown)
    @          0x1051e5d        192  frontend::(anonymous namespace)::NextSlashInitiatedToken()
    @          0x1050997        816  frontend::NextToken()
    @          0x10502d4        144  frontend::Lex()
    @           0xff1aae        608  frontend::Parse()
    @           0xf70b61       1920  compiler::(anonymous namespace)::Interpret()
    @           0xf70431        800  main
    @     0x7f88c47d6fd0  (unknown)  (unknown)
Segmentation fault (core dumped)

Input 2:

foo := 0
// blah

Output:

Error:
Encountered unprintable character '\x00' encountered in source.

[140442242041672 frontend/source_indexer.cc:48 EntryFor] Unreachable code-path.
()
*** SIGABRT received at time=1649300956 on cpu 4 ***
PC: @     0x7fbb41fc7828  (unknown)  pthread_kill
    @          0x15023c0         64  absl::WriteFailureInfo()
    @          0x15020a4        224  absl::AbslFailureSignalHandler()
    @     0x7fbb41f73520  (unknown)  (unknown)
Aborted (core dumped)
asoffer commented 2 years ago

Definitely still report parsing bugs, but I'm not going to work on them actively. I'm working on rewriting the parser from a shift-reduce to a recursive-descent. it's significantly more testable and fuzzable. I suspect a lot of the parsing bugs will go away when that branch gets merged into main.

perimosocordiae commented 2 years ago

Oh nice! Maybe a good addition to the test suite, then.