JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
85 stars 3 forks source link

Automatically convert last expression to return #360

Closed JSAbrahams closed 1 year ago

JSAbrahams commented 1 year ago

Relevant issues

Resolves #164

Summary

Function with return last item in function body. We do this by making use of the state in the generate stage. When a function has a return in the signature, a flag is set in the state. This flag is then used in the generate of the body, but it is not propagated further to prevent returns being inserted deep within the AST where they shouldn't be. If set to true, then we in most situations wrap the final item of the function body in a core return node. Exceptions are explained below.

If function body does not end with an expression, then the check stage already gives an error (we tested this before, right? Maybe check). We have some exceptions:

Also exposed a weird error in check stage. In function/definition.mamba, line 7: Change if True then return 10 else return None To if True then 10 else None Gives type error: Unifying two types: Expected an Int, was a None Not something to fix in this PR, it is erroneous behaviour as the mamba script is well-typed according to current spec.

Added Tests

JSAbrahams commented 1 year ago

The "weird error" in the check stage, at first glance, would appear to be related to #296

codecov[bot] commented 1 year ago

Codecov Report

Merging #360 (2198785) into develop (e90633d) will increase coverage by 0.01%. The diff coverage is 92.59%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #360      +/-   ##
===========================================
+ Coverage    86.96%   86.97%   +0.01%     
===========================================
  Files          108      108              
  Lines        11705    11727      +22     
===========================================
+ Hits         10179    10200      +21     
- Misses        1526     1527       +1