Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/ltk_ritobin/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ entries: map[hash, embed] = {
assert_success(r#"mVelMultiplier: f32 = 0 # asd"#);
}

#[test]
fn unterminated_string_value() {
let text = "name: string = \"\n";
let cst = Cst::parse(text);
assert!(!cst.errors.is_empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you assert that the error list here is exactly the one error we expect?


// used to panic on the error tree left behind by the tokenizer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't needed

let (_bin, _errors) = cst.build_bin(text);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also assert that _errors is empty here (we rely on users of this crate to check for parse errors before assuming the resulting bin is valid, so there should be no typechecker-specific errors here)

}

#[ignore = "Nice to have"]
#[test]
fn naked_class() {
Expand Down
6 changes: 5 additions & 1 deletion crates/ltk_ritobin/src/typecheck/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ pub(crate) fn resolve_value(
let Some(child) = children.get(visit_ctx.cst).first() else {
return Ok(None);
};
return resolve_literal(ctx, child.token(visit_ctx.cst).unwrap(), kind_hint);
// an unterminated string leaves an error tree here instead of a token
let Some(token) = child.token(visit_ctx.cst) else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead and_then this with the above child binding? We also don't need the comment, since there can be many reasons the next node isn't a token.

return Ok(None);
};
return resolve_literal(ctx, token, kind_hint);
}
_ => return Ok(None),
}))
Expand Down