🐞️ Functions: Expressionless return and enforcing requirement #113

Closed
opened 2023-04-21 07:52:43 +01:00 by deavmi · 20 comments
Owner

Bugfix 🐞️: Expressionless return

Allow a return without an expression:

  • Must be allowed at the parser level
  • Dependency generation must check if an expression exists and only then proceed, else we call expressionPass(null) (on null)
  • Typechecking, we must match function's return type with the type of the return instruction generated and if there is a void type then no expression can be present
  • Typechecking enforce it be present in non-void function declarations
  • Should only be allowed in a function, see where we should do this
    • Solution1: Could be done in the parser technically but I feel that would require us to check anything that has a parseBody() call in it and that feels wrong.
    • Solution 2: We could specifically check, when processing the ReturnStmt in the typechecker/code gen what it's parentOf is and then that would allow us, for ANY return statement to ensure it is in a Container that is a Function only
    • Update: Regarding this it only complains actually when not in parseBody(), I don't have an example fo wehere we use parseBody() in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we did come up with some structure that used parseBody() but would not allow return in it then this would be a good way to check for it.
  • Enforce that a function of a non-void type MUST have a return expression.
    • This can be done in the parser when we check for the stuff we do in #112
## Bugfix 🐞️: Expressionless `return` Allow a `return` without an expression: - [x] Must be allowed at the parser level - [x] Dependency generation must check if an expression exists and only then proceed, else we call `expressionPass(null)` (on null) - [x] Typechecking, we must match function's return type with the type of the return instruction generated and if there is a `void` type then no expression can be present - [x] Typechecking enforce it be present in non-`void` function declarations - [x] Should only be allowed in a function, see where we should do this * **Solution1:** Could be done in the parser technically but I feel that would require us to check anything that has a `parseBody()` call in it and that feels wrong. * **Solution 2:** We could specifically check, when processing the `ReturnStmt` in the typechecker/code gen what it's `parentOf` is and then that would allow us, for ANY `return` statement to ensure it is in a `Container` that is a `Function` only * **Update:** Regarding this it only complains actually when not in `parseBody()`, I don't have an example fo wehere we use `parseBody()` in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we _did_ come up with some structure that used `parseBody()` but would not allow `return` in it then this would be a good way to check for it. - [x] Enforce that a function of a non-void type MUST have a `return` expression. * This can be done in the parser when we check for the stuff we do in #112
deavmi added the
typing
parser
labels 2023-04-21 07:54:09 +01:00
deavmi self-assigned this 2023-04-21 07:54:12 +01:00
deavmi added this to the Dependency tree, type-checking and codegen project 2023-04-21 07:54:15 +01:00
deavmi added this to the Basics milestone 2023-04-21 07:54:18 +01:00
deavmi added the due date 2023-04-21 2023-04-21 07:54:23 +01:00
deavmi started working 2023-04-21 07:54:24 +01:00
deavmi added reference bugfix/return_type 2023-04-21 07:55:20 +01:00
deavmi added the
dependency
label 2023-04-21 08:06:32 +01:00
Author
Owner

As of commit 4facc5a3f0f32eae1a5fe8c1e0a3809e4cfddf49 we have added support for expressionless returns in the parser and CI/CD checks out

As of commit `4facc5a3f0f32eae1a5fe8c1e0a3809e4cfddf49` we have added support for expressionless returns in the parser and CI/CD checks out ✅
deavmi stopped working 2023-04-21 08:09:02 +01:00
14 minutes 38 seconds
deavmi started working 2023-04-21 08:26:29 +01:00
Author
Owner

As of commit 98f6c03d22457b63f1998b3c9056a05a587e72f2 we have added a check in the dependency generator to only do expressionPass() when the ReturnStmt has an expression.

Running typecheck test in CI passes , so this is good

As of commit `98f6c03d22457b63f1998b3c9056a05a587e72f2` we have added a check in the dependency generator to only do `expressionPass()` when the `ReturnStmt` has an expression. Running `typecheck` test in CI passes ✅ , so this is good
deavmi stopped working 2023-04-21 08:31:44 +01:00
5 minutes 15 seconds
deavmi added a new dependency 2023-04-21 09:06:45 +01:00
deavmi added a new dependency 2023-04-21 14:11:52 +01:00
Author
Owner

Going to bring this branch's base up-to-date.

Going to bring this branch's base up-to-date.
Author
Owner

Going to bring this branch's base up-to-date.

Done and CI fails where it normally did

> Going to bring this branch's base up-to-date. Done and CI fails where it normally did ✅
deavmi added a new dependency 2023-04-21 14:37:01 +01:00
Author
Owner

Not continueing this until I get universal coercion working as that makes sense to do rather than coerce everywhere where I could.

Not continueing this until I get universal coercion working as that makes sense to do rather than coerce everywhere where I could.
deavmi started working 2023-07-11 20:14:42 +01:00
Author
Owner

Taking a look at this again...

Taking a look at this again...
Author
Owner

Looks good to me

Looks good to me
Author
Owner

Fixed merge conflict 👍

Fixed merge conflict 👍
Author
Owner

Awaiting CI/CD...

Awaiting CI/CD...
deavmi stopped working 2023-07-11 21:45:45 +01:00
1 hour 31 minutes
deavmi changed reference from bugfix/return_type to vardec_varass_dependency 2023-07-12 08:56:49 +01:00
deavmi changed reference from vardec_varass_dependency to vardec_varass_dependency 2023-07-12 08:58:13 +01:00
deavmi added spent time 2023-07-12 08:58:20 +01:00
10 minutes
deavmi started working 2023-07-12 08:58:22 +01:00
Author
Owner

Fixed the lookup of the ReturnStmt's nearest Function-based Container.

Fixed the lookup of the `ReturnStmt`'s nearest `Function`-based `Container`.
deavmi modified the due date from 2023-04-21 to 2023-07-12 2023-07-12 09:02:33 +01:00
deavmi modified the due date from 2023-07-12 to 2023-07-30 2023-07-12 09:02:37 +01:00
Author
Owner

This will now continue on the feature/universal_coercion branch so I can do the type checking part.

This will now continue on the `feature/universal_coercion` branch so I can do the type checking part.
deavmi changed reference from vardec_varass_dependency to feature/universal_coercion 2023-07-12 09:04:09 +01:00
Author
Owner

This will now continue on the feature/universal_coercion branch so I can do the type checking part.

Working on merge conflicts now...

> This will now continue on the `feature/universal_coercion` branch so I can do the type checking part. Working on merge conflicts now...
Author
Owner

This will now continue on the feature/universal_coercion branch so I can do the type checking part.

Working on merge conflicts now...

Merged 👍

Added a TODO where the type enforcement needs to go

> > This will now continue on the `feature/universal_coercion` branch so I can do the type checking part. > > Working on merge conflicts now... Merged 👍 Added a TODO where the type enforcement needs to go
deavmi stopped working 2023-07-12 09:08:37 +01:00
10 minutes 15 seconds
deavmi started working 2023-07-12 09:59:58 +01:00
Author
Owner

Type enforcement added in commit 0a4cec2013d932c7b4e33a8a7508002047f94db4 on the feature/universal_coercion branch

Type enforcement added in commit `0a4cec2013d932c7b4e33a8a7508002047f94db4` on the `feature/universal_coercion` branch
Author
Owner

Initial CI/CD all green

Initial CI/CD all green ✅
Author
Owner

Added two new test cases:

  1. simple_function_return_type_check_bad.t
    • Good failer
  2. simple_function_return_type_check_good.t
    • Good passer

In commit dd66d2e47e6910bc10634f9a26814a97c7fcf830 in branch as above 2nd last comment to this one

Added two new test cases: 1. `simple_function_return_type_check_bad.t` * Good failer 2. `simple_function_return_type_check_good.t` * Good passer In commit `dd66d2e47e6910bc10634f9a26814a97c7fcf830` in branch as above 2nd last comment to this one
Author
Owner

Added two new test cases:

  1. simple_function_return_type_check_bad.t
    * Good failer
  2. simple_function_return_type_check_good.t
    * Good passer

In commit dd66d2e47e6910bc10634f9a26814a97c7fcf830 in branch as above 2nd last comment to this one

CI/CD all good

> Added two new test cases: > > 1. `simple_function_return_type_check_bad.t` > * Good failer > 2. `simple_function_return_type_check_good.t` > * Good passer > > In commit `dd66d2e47e6910bc10634f9a26814a97c7fcf830` in branch as above 2nd last comment to this one CI/CD all good ✅
Author
Owner

Bugfix 🐞️: Expressionless return

Allow a return without an expression:

  • Must be allowed at the parser level
  • Dependency generation must check if an expression exists and only then proceed, else we call expressionPass(null) (on null)
  • Typechecking, we must match function's return type with the type of the return instruction generated and if there is a void type then no expression can be present
  • Typechecking enforce it be present in non-void function declarations
  • Should only be allowed in a function, see where we should do this
    • Solution1: Could be done in the parser technically but I feel that would require us to check anything that has a parseBody() call in it and that feels wrong.
    • Solution 2: We could specifically check, when processing the ReturnStmt in the typechecker/code gen what it's parentOf is and then that would allow us, for ANY return statement to ensure it is in a Container that is a Function only
    • Update: Regarding this it only complains actually when not in parseBody(), I don't have an example fo wehere we use parseBody() in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we did come up with some structure that used parseBody() but would not allow return in it then this would be a good way to check for it.
  • Enforce that a function of a non-void type MUST have a return expression.
    • This can be done in the parser when we check for the stuff we do in #112

Last bullet point that I need to look at now

> ## Bugfix 🐞️: Expressionless `return` > > Allow a `return` without an expression: > > - [x] Must be allowed at the parser level > - [x] Dependency generation must check if an expression exists and only then proceed, else we call `expressionPass(null)` (on null) > - [x] Typechecking, we must match function's return type with the type of the return instruction generated and if there is a `void` type then no expression can be present > - [x] Typechecking enforce it be present in non-`void` function declarations > - [ ] Should only be allowed in a function, see where we should do this > * **Solution1:** Could be done in the parser technically but I feel that would require us to check anything that has a `parseBody()` call in it and that feels wrong. > * **Solution 2:** We could specifically check, when processing the `ReturnStmt` in the typechecker/code gen what it's `parentOf` is and then that would allow us, for ANY `return` statement to ensure it is in a `Container` that is a `Function` only > * **Update:** Regarding this it only complains actually when not in `parseBody()`, I don't have an example fo wehere we use `parseBody()` in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we _did_ come up with some structure that used `parseBody()` but would not allow `return` in it then this would be a good way to check for it. > - [x] Enforce that a function of a non-void type MUST have a `return` expression. > * This can be done in the parser when we check for the stuff we do in #112 > Last bullet point that I need to look at now
deavmi stopped working 2023-07-12 10:05:19 +01:00
5 minutes 21 seconds
deavmi modified the due date from 2023-07-30 to 2023-07-15 2023-07-12 10:08:57 +01:00
Author
Owner

Bugfix 🐞️: Expressionless return

Allow a return without an expression:

  • Must be allowed at the parser level
  • Dependency generation must check if an expression exists and only then proceed, else we call expressionPass(null) (on null)
  • Typechecking, we must match function's return type with the type of the return instruction generated and if there is a void type then no expression can be present
  • Typechecking enforce it be present in non-void function declarations
  • Should only be allowed in a function, see where we should do this
    • Solution1: Could be done in the parser technically but I feel that would require us to check anything that has a parseBody() call in it and that feels wrong.
    • Solution 2: We could specifically check, when processing the ReturnStmt in the typechecker/code gen what it's parentOf is and then that would allow us, for ANY return statement to ensure it is in a Container that is a Function only
    • Update: Regarding this it only complains actually when not in parseBody(), I don't have an example fo wehere we use parseBody() in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we did come up with some structure that used parseBody() but would not allow return in it then this would be a good way to check for it.
  • Enforce that a function of a non-void type MUST have a return expression.
    • This can be done in the parser when we check for the stuff we do in #112

Last bullet point that I need to look at now

Accounted for via:

if(!funcContainer)
{
	throw new TypeCheckerException(this, TypeCheckerException.TypecheckError.GENERAL_ERROR, "A return statement can only appear in the body of a function");
}
> > ## Bugfix 🐞️: Expressionless `return` > > > > Allow a `return` without an expression: > > > > - [x] Must be allowed at the parser level > > - [x] Dependency generation must check if an expression exists and only then proceed, else we call `expressionPass(null)` (on null) > > - [x] Typechecking, we must match function's return type with the type of the return instruction generated and if there is a `void` type then no expression can be present > > - [x] Typechecking enforce it be present in non-`void` function declarations > > - [ ] Should only be allowed in a function, see where we should do this > > * **Solution1:** Could be done in the parser technically but I feel that would require us to check anything that has a `parseBody()` call in it and that feels wrong. > > * **Solution 2:** We could specifically check, when processing the `ReturnStmt` in the typechecker/code gen what it's `parentOf` is and then that would allow us, for ANY `return` statement to ensure it is in a `Container` that is a `Function` only > > * **Update:** Regarding this it only complains actually when not in `parseBody()`, I don't have an example fo wehere we use `parseBody()` in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we _did_ come up with some structure that used `parseBody()` but would not allow `return` in it then this would be a good way to check for it. > > - [x] Enforce that a function of a non-void type MUST have a `return` expression. > > * This can be done in the parser when we check for the stuff we do in #112 > > > > Last bullet point that I need to look at now Accounted for via: ```d if(!funcContainer) { throw new TypeCheckerException(this, TypeCheckerException.TypecheckError.GENERAL_ERROR, "A return statement can only appear in the body of a function"); } ```
deavmi started working 2023-07-13 12:28:50 +01:00
Author
Owner

Bugfix 🐞️: Expressionless return

Allow a return without an expression:

  • Must be allowed at the parser level
  • Dependency generation must check if an expression exists and only then proceed, else we call expressionPass(null) (on null)
  • Typechecking, we must match function's return type with the type of the return instruction generated and if there is a void type then no expression can be present
  • Typechecking enforce it be present in non-void function declarations
  • Should only be allowed in a function, see where we should do this
    • Solution1: Could be done in the parser technically but I feel that would require us to check anything that has a parseBody() call in it and that feels wrong.
    • Solution 2: We could specifically check, when processing the ReturnStmt in the typechecker/code gen what it's parentOf is and then that would allow us, for ANY return statement to ensure it is in a Container that is a Function only
    • Update: Regarding this it only complains actually when not in parseBody(), I don't have an example fo wehere we use parseBody() in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we did come up with some structure that used parseBody() but would not allow return in it then this would be a good way to check for it.
  • Enforce that a function of a non-void type MUST have a return expression.
    • This can be done in the parser when we check for the stuff we do in #112

Last bullet point that I need to look at now

Accounted for via:

if(!funcContainer)
{
	throw new TypeCheckerException(this, TypeCheckerException.TypecheckError.GENERAL_ERROR, "A return statement can only appear in the body of a function");
}

All done on commit b01ff34daadcdc53c43d650500f3ebb9a9cc0457

CI/CD :chec

> > > ## Bugfix 🐞️: Expressionless `return` > > > > > > Allow a `return` without an expression: > > > > > > - [x] Must be allowed at the parser level > > > - [x] Dependency generation must check if an expression exists and only then proceed, else we call `expressionPass(null)` (on null) > > > - [x] Typechecking, we must match function's return type with the type of the return instruction generated and if there is a `void` type then no expression can be present > > > - [x] Typechecking enforce it be present in non-`void` function declarations > > > - [ ] Should only be allowed in a function, see where we should do this > > > * **Solution1:** Could be done in the parser technically but I feel that would require us to check anything that has a `parseBody()` call in it and that feels wrong. > > > * **Solution 2:** We could specifically check, when processing the `ReturnStmt` in the typechecker/code gen what it's `parentOf` is and then that would allow us, for ANY `return` statement to ensure it is in a `Container` that is a `Function` only > > > * **Update:** Regarding this it only complains actually when not in `parseBody()`, I don't have an example fo wehere we use `parseBody()` in a non-function, thereore so far having such a check wouldn't matter actually. I don't necessarily feels as though this is bad because if for some reason we _did_ come up with some structure that used `parseBody()` but would not allow `return` in it then this would be a good way to check for it. > > > - [x] Enforce that a function of a non-void type MUST have a `return` expression. > > > * This can be done in the parser when we check for the stuff we do in #112 > > > > > > > Last bullet point that I need to look at now > > Accounted for via: > > ```d > if(!funcContainer) > { > throw new TypeCheckerException(this, TypeCheckerException.TypecheckError.GENERAL_ERROR, "A return statement can only appear in the body of a function"); > } > ``` All done on commit `b01ff34daadcdc53c43d650500f3ebb9a9cc0457` CI/CD :chec
deavmi stopped working 2023-07-13 12:34:43 +01:00
5 minutes 53 seconds
deavmi removed a dependency 2023-07-13 12:34:53 +01:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Total Time Spent: 2 hours 22 minutes
deavmi
2 hours 22 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-07-15

Depends on
You do not have permission to read 1 dependency
Reference: tlang/tlang#113
No description provided.