From e08f6c8d8d30fae490e61d7d350b06cb6dd1d269 Mon Sep 17 00:00:00 2001 From: Glyphack Date: Sun, 6 Aug 2023 18:09:04 +0200 Subject: [PATCH] Add test for return statements in functions --- typechecker/src/build.rs | 1 + typechecker/src/semantic_analyzer.rs | 4 +--- .../typechecker__build__tests__assign_stmt-3.snap | 8 ++++---- .../typechecker__build__tests__assign_stmt-6.snap | 14 +++++++++++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/typechecker/src/build.rs b/typechecker/src/build.rs index 223870a0..7ad5f3d7 100644 --- a/typechecker/src/build.rs +++ b/typechecker/src/build.rs @@ -113,6 +113,7 @@ mod tests { "a += b", "def f(): a = 1 + return ", ]; for source in sources { diff --git a/typechecker/src/semantic_analyzer.rs b/typechecker/src/semantic_analyzer.rs index 15f061d6..448ccd5b 100644 --- a/typechecker/src/semantic_analyzer.rs +++ b/typechecker/src/semantic_analyzer.rs @@ -444,9 +444,7 @@ impl TraversalVisitor for SemanticAnalyzer { todo!() } - fn visit_return(&mut self, r: &parser::ast::Return) { - todo!() - } + fn visit_return(&mut self, r: &parser::ast::Return) {} fn visit_raise(&mut self, r: &parser::ast::Raise) { todo!() diff --git a/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-3.snap b/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-3.snap index 3a918a3b..1d0e505d 100644 --- a/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-3.snap +++ b/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-3.snap @@ -7,8 +7,8 @@ SymbolTable { SymbolTableScope { symbol_table_type: Module, symbols: { - "c": SymbolTableNode { - name: "c", + "d": SymbolTableNode { + name: "d", declarations: [ Variable( Variable { @@ -63,8 +63,8 @@ SymbolTable { module_hidden: false, implicit: false, }, - "d": SymbolTableNode { - name: "d", + "c": SymbolTableNode { + name: "c", declarations: [ Variable( Variable { diff --git a/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-6.snap b/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-6.snap index 8fbdeb4e..6ce0592b 100644 --- a/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-6.snap +++ b/typechecker/src/snapshots/typechecker__build__tests__assign_stmt-6.snap @@ -1,6 +1,6 @@ --- source: typechecker/src/build.rs -description: "def f():\n a = 1\n" +description: "def f():\n a = 1\n return\n" --- SymbolTable { scopes: [ @@ -16,12 +16,20 @@ SymbolTable { module_name: "test", node: Node { start: 0, - end: 18, + end: 28, }, }, is_method: false, is_generator: false, - return_statements: [], + return_statements: [ + Return { + node: Node { + start: 18, + end: 27, + }, + value: None, + }, + ], yeild_statements: [], raise_statements: [], },