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) => {} } }