jakt
jakt copied to clipboard
Parser: Jakt panics while trying to parse enum initialization that contains enums
enum Register {
Rax
Rbx
}
enum OpCode {
Add(lhs: Register, rhs: Register)
}
function main() {
let x = OpCode::Add(lhs:: Register::Rax, rhs: Register::Rbx);
}
Expected output: Parser error Actual output:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/typechecker.rs:4511:34
stack backtrace:
0: rust_begin_unwind
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
2: core::panicking::panic
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:48:5
3: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
4: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
5: jakt::typechecker::typecheck_expression
6: jakt::typechecker::typecheck_call
7: jakt::typechecker::typecheck_expression
8: jakt::typechecker::typecheck_statement
9: jakt::typechecker::typecheck_block
10: jakt::typechecker::typecheck_function
11: jakt::typechecker::typecheck_namespace_declarations
12: jakt::typechecker::typecheck_module
13: jakt::compiler::Compiler::check_project
14: jakt::compiler::Compiler::convert_to_cpp
15: jakt::main
looking at the arguments that the parser got, I've found that the first argument has no name, and that the name is instead the namespace. Makes sense, since we don't enforce that no whitespace comes after ::
:
args: [
(
"",
NamespacedVar(
"Rax",
[
"lhs",
"Register",
],
Span {
file_id: 1,
start: 124,
end: 144,
},
),
),
(
"rhs",
NamespacedVar(
"Rbx",
[
"Register",
],
Span {
file_id: 1,
start: 150,
end: 164,
},
),
),
],
The parser is correct, so the typechecker must be doing some wrong assumptions on that unwrap
.
fixed as of 1ea81c6