This commit is contained in:
Edgar 2023-03-25 16:25:12 +01:00
parent a1944fe1ce
commit c68daa2d93
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
2 changed files with 62 additions and 3 deletions

View file

@ -1,4 +1,3 @@
let x = 2;
fn add(a: i64, b: i64) -> i64 { fn add(a: i64, b: i64) -> i64 {
return a + b; return a + b;
} }

View file

@ -50,8 +50,68 @@ pub fn check<'a>(data: &'a ProgramData, ast: &ast::Program) -> Vec<Check<'a>> {
let dl = DisplayList::from(snippet); let dl = DisplayList::from(snippet);
errors.push(Check::Error(dl)); errors.push(Check::Error(dl));
} }
Statement::Definition(_) => todo!(), Statement::Definition(_) => {
Statement::Return(_) => unreachable!(), // can't have a top level assignment yet.
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some("unexpected definition at top level"),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
source: &data.source,
line_start: 1,
fold: true,
origin: Some(&data.filename),
annotations: vec![
SourceAnnotation {
label: "unexpected statement",
annotation_type: AnnotationType::Error,
range: statement.span.into(),
},
],
}],
opt: FormatOptions {
color: true,
..Default::default()
},
};
let dl = DisplayList::from(snippet);
errors.push(Check::Error(dl));
},
Statement::Return(_x) => {
// can't have a top level assignment yet.
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some("unexpected return"),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
source: &data.source,
line_start: 1,
fold: true,
origin: Some(&data.filename),
annotations: vec![
SourceAnnotation {
label: "unexpected return",
annotation_type: AnnotationType::Error,
range: statement.span.into(),
},
],
}],
opt: FormatOptions {
color: true,
..Default::default()
},
};
let dl = DisplayList::from(snippet);
errors.push(Check::Error(dl));
},
Statement::Function(_function) => {} Statement::Function(_function) => {}
} }
} }