sway
sway copied to clipboard
Return a typed AST even if type checking fails
Consider the following example that rightfully fails type checking.
script;
fn main() {
let y: u64 = 0;
let x: str[3] = y;
}
Currently, the compiler is returning warnings and errors but not a typed AST.
CompileResult {
value: None,
warnings: [],
errors: [
TypeError(
MismatchedType {
expected: str[3],
received: u64,
help_text: "Variable declaration's type annotation does not match up with the assigned expression's type.",
span: Span {
src (ptr): 0x000055bcdd85f180,
path: Some(
"/home/josh/rust/fuel/sway/sway-lsp/test_programs/scratch_pad/src/main.sw",
),
start: 61,
end: 62,
as_str(): "y",
},
},
),
],
}
Although the let x line is the part that can't be type checked, we still need the typed AST returned so we can inspect the types for parts of the code that did pass type checking.