Conversation
|
Hello @evhub. Thank you for the open-source contribution opportunity Currently I am trying to figure out how to make the detection work with # validate-issue-599.coco
yield def yield_f():
return 1Result: Compiling validate-issue-599.coco ...
CoconutStyleError: found unreachable code after return statement (remove --strict to downgrade to a warning) (line 1 in 'validate-issue-599.coco')
yield def yield_f():
Coconut exiting with error: CoconutStyleErrorComplied Python file: def yield_f(): #1 (line in Coconut source)
raise _coconut.StopIteration((1)) #2 (line in Coconut source)
if False: #3 (line in Coconut source)
yield #3 (line in Coconut source)There are some ideas that I can think of:
At this point, I am unsure if my solution is heading in the right direction, and I would appreciate some guidance if possible 😅. |
|
Hello! I decided to go with the fix Now the complied code is like this: Coconut file: # validate-issue-599.coco
yield def yield_f_without_docstring():
return 1
yield def yield_f_with_docstring():
"""docstring"""
return 1Complied Python file: # Compiled Coconut: -----------------------------------------------------------
def yield_f_without_docstring(): #1 (line in Coconut source)
if False: #2 (line in Coconut source)
yield #2 (line in Coconut source)
raise _coconut.StopIteration((1)) #2 (line in Coconut source)
def yield_f_with_docstring(): #4 (line in Coconut source)
"""docstring""" #5 (line in Coconut source)
if False: #6 (line in Coconut source)
yield #6 (line in Coconut source)
raise _coconut.StopIteration((1)) #6 (line in Coconut source)
If there’s another approach that I should consider, please let me know. |
This pull request implement solution for the issue #599
Changes
proc_funcdefduringdeferred_code_procit_ret,it_ret_none, andit_ret_tupleintarget_sys_test.cocoto avoid triggering the unreachable code checkerkeyword_funcdef_handleto move the generated yield statement to the top of the function (after docstring if any) to avoid trigger the unreachable code checkerExamples
With
--strict:Without
--strict:Limitations
return,raise) at the top level of function bodies