待辦事項 #35232

eval "return" does not return from function

啟用日期: 2015-06-12 10:02 最後更新: 2015-07-05 23:56

回報者:
負責人:
類型:
狀態:
關閉
元件:
里程碑:
(無)
優先權:
5 - 中
嚴重程度:
5 - 中
處理結果:
修正
檔案:
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

細節

When executing a function, and "return" is encountered within an "eval" statement, yash does not return from the function; instead, it only stops executing the "eval" and continues the function after it. Every other shell (bash, *ksh*, zsh, (d)ash, etc.) returns from the function.

testfn() {
    echo 1
    eval "echo 2; return; echo 3"
    echo 4
}
testfn

Actual output:

1
2
4

Expected output:

1
2

Example of real-life use case: unset some temporary variables, then return with the exit code of the command preceding the 'eval'. Using 'eval' removes the need to store the exit status in a variable. This bug makes it harder to do this in yash -- eval does exit with the saved status, but then in yash, another "return" is needed after the eval.

eval "unset -v temp1 temp2; return $?"

Ticket History (3/4 Histories)

2015-06-12 10:02 Updated by: mcdutchie
  • New Ticket "eval "return" does not return from function" created
2015-06-12 22:01 Updated by: mcdutchie
  • 元件 Update from (無) to shell-builtin
  • 負責人 Update from (無) to magicant
2015-06-12 22:24 Updated by: magicant
評語

Hmm. The cancel_return call at the end of the parse_and_exec function is not doing the right thing.

2015-07-05 23:56 Updated by: magicant
  • 處理結果 Update from to 修正
  • 狀態 Update from 開啟 to 關閉
  • Ticket Close date is changed to 2015-07-05 23:56
評語

Fixed in r3316

Thanks for reporting!

Attachment File List

No attachments

編輯

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » 登入