“Dead method context” error in a function

后端 未结 2 641
不思量自难忘°
不思量自难忘° 2021-01-23 01:32

I am trying to write a isBinary function that checks sent line if it has any non-printable characters (integer value outside range 0-127):

isBinary         


        
2条回答
  •  时光说笑
    2021-01-23 02:25

    Your isBinary variable is bound to a block that contains a so called non-local return, which cannot be executed the way you intend. The reason is that the semantics for a non-local return is to return from the method that defines de block (it's lexical context). If such a method does not exist or it already returned (in other words if the lexical context is not in the calling stack), there is no way to define where the execution flow should return. Hence the error.

    To solve this, just create a method #isBinary: that receives an argument sline with the code you wrote for the block. Then call the method instead of evaluating the block. That will work.

提交回复
热议问题