http://www.perlmonks.org?node_id=773788


in reply to Re^2: return if 0
in thread return if 0

To be fair, it wouldn't be insane for the compiler to know that the block can never execute, and just remove it completely.

Except for the part that it has unexpected consequences, as we've been discussing.

-- zigdon

Replies are listed 'Best First'.
Re^4: return if 0
by ikegami (Patriarch) on Jun 23, 2009 at 01:02 UTC
    It does remove the if, but it keeps the constant to maintain the behaviour.
    >perl -MO=Concise,-exec,f -e"sub f { return 1 if 0 }" main::f: 1 <;> nextstate(main 1 -e:1) v 2 <$> const[IV 0] s/SHORT 3 <1> leavesub[1 ref] K/REFC,1 -e syntax OK

    Compared to:

    >perl -MO=Concise,-exec,f -e"sub f { return 1 if $c }" main::f: 1 <;> nextstate(main 1 -e:1) v 2 <#> gvsv[*c] s 3 <|> and(other->4) K/1 4 <0> pushmark s 5 <$> const[IV 1] s 6 <@> return K 7 <1> leavesub[1 ref] K/REFC,1 -e syntax OK

    Note the and operator (used to implement if) is missing from the first snippet.