Repository: syuilo/aiscript
Pull request #222 (2023-01-05 06:23:04)

fix: return statement in the for statement
<!-- ℹ お読みください
PRありがとうございます！ PRを作成する前に、以下をご確認ください:
- 可能であればタイトルに、以下で示すようなPRの種類が分かるキーワードをプリフィクスしてください。
  - fix / refactor / feat / enhance / perf / chore
  - また、PRの粒度が適切であることを確認してください。ひとつのPRに複数の種類の変更や関心を含めることは避けてください。
- このPRによって解決されるIssueがある場合は、そのIssueへの参照を本文内に含めてください。
- CHANGELOG.mdに変更点を追記してください。リファクタリングなど、利用者に影響を与えない変更についてはこの限りではありません。
- この変更により新たに作成、もしくは更新すべきドキュメントがないか確認してください。
- 機能追加やバグ修正をした場合は、可能であればテストケースを追加してください。
- テスト、Lintが通っていることを予め確認してください。
  - `npm run test`、`npm run lint`でぞれぞれ実施可能です
- `npm run api`を実行してAPIレポートを更新し、差分がある場合はコミットしてください。
ご協力ありがとうございます🤗
-->
<!-- ℹ README
Thank you for your PR! Before creating a PR, please check the following:
- If possible, prefix the title with a keyword that identifies the type of this PR, as shown below.
  - fix / refactor / feat / enhance / perf / chore
  - Also, make sure that the granularity of this PR is appropriate. Please do not include more than one type of change or interest in a single PR.
- If there is an Issue which will be resolved by this PR, please include a reference to the Issue in the text.
- Please add the summary of the changes to CHANGELOG.md. However, this is not necessary for changes that do not affect the users, such as refactoring.
- Check if there are any documents that need to be created or updated due to this change.
- If you have added a feature or fixed a bug, please add a test case if possible.
- Please make sure that tests and Lint are passed in advance.
  - You can run it with `npm run test` and `npm run lint`.
- Run `npm run api` to update the API report and commit it if there are any diffs.
Thanks for your cooperation 🤗
-->

# What
<!-- このPRで何をしたのか？ どう変わるのか？ -->
<!-- What did you do with this PR? How will it change things? -->
for文でreturnした時に、後続の処理が実行されてしまうバグを修正します。

# Why
<!-- なぜそうするのか？ どういう意図なのか？ 何が困っているのか？ -->
<!-- Why do you do it? What are your intentions? What is the problem? -->

# Additional info (optional)
<!-- テスト観点など -->
<!-- Test perspective, etc -->


marihachi: ちょっとテスト書くかも
codecov[bot]: # [Codecov](https://codecov.io/gh/syuilo/aiscript/pull/222?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo) Report
Base: **86.53**% // Head: **86.53**% // No change to project coverage :thumbsup:
> Coverage data is based on head [(`dde75d1`)](https://codecov.io/gh/syuilo/aiscript/pull/222?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo) compared to base [(`b211186`)](https://codecov.io/gh/syuilo/aiscript/commit/b2111867b6d6515aaea36b2744e008adf908b0af?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo).
> Patch coverage: 50.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #222   +/-   ##
=======================================
  Coverage   86.53%   86.53%           
=======================================
  Files          19       19           
  Lines        2770     2770           
  Branches      430      430           
=======================================
  Hits         2397     2397           
  Misses        366      366           
  Partials        7        7           
```


| [Impacted Files](https://codecov.io/gh/syuilo/aiscript/pull/222?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo) | Coverage Δ | |
|---|---|---|
| [src/interpreter/index.ts](https://codecov.io/gh/syuilo/aiscript/pull/222?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo#diff-c3JjL2ludGVycHJldGVyL2luZGV4LnRz) | `90.25% <50.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/syuilo/aiscript/pull/222?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=syuilo).

marihachi: 良さそう:tada:

Patch:
diff --git a/src/interpreter/index.ts b/src/interpreter/index.ts
index f56fb6d..8973ece 100644
--- a/src/interpreter/index.ts
+++ b/src/interpreter/index.ts
@@ -251,7 +251,7 @@ export class Interpreter {
 						if (v.type === 'break') {
 							break;
 						} else if (v.type === 'return') {
-							return v.value;
+							return v;
 						}
 					}
 				} else {
@@ -266,7 +266,7 @@ export class Interpreter {
 						if (v.type === 'break') {
 							break;
 						} else if (v.type === 'return') {
-							return v.value;
+							return v;
 						}
 					}
 				}


Test patch:
diff --git a/test/index.ts b/test/index.ts
index 4df455b..0317f67 100644
--- a/test/index.ts
+++ b/test/index.ts
@@ -1044,6 +1044,19 @@ describe('Return', () => {
 		eq(res, NUM(43));
 	});
 
+	test.concurrent('return inside for 2', async () => {
+		const res = await exe(`
+		@f() {
+  		for (let i, 10) {
+    		return 1
+  		}
+  		2
+		}
+		<: f()
+		`);
+		eq(res, NUM(1));
+	});
+
 	test.concurrent('return inside loop', async () => {
 		const res = await exe(`
 		@f() {