From c68daa2d93b16a8642b4c5a6406e8010cd951e7a Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Sat, 25 Mar 2023 16:25:12 +0100 Subject: [PATCH] check --- example.ed | 1 - src/check.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/example.ed b/example.ed index 75b4d0b5c..17ea20b34 100644 --- a/example.ed +++ b/example.ed @@ -1,4 +1,3 @@ -let x = 2; fn add(a: i64, b: i64) -> i64 { return a + b; } diff --git a/src/check.rs b/src/check.rs index 226aaeba6..1a7226f0f 100644 --- a/src/check.rs +++ b/src/check.rs @@ -50,8 +50,68 @@ pub fn check<'a>(data: &'a ProgramData, ast: &ast::Program) -> Vec> { let dl = DisplayList::from(snippet); errors.push(Check::Error(dl)); } - Statement::Definition(_) => todo!(), - Statement::Return(_) => unreachable!(), + Statement::Definition(_) => { + // 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) => {} } }