An 'unreportable' perl bug revisited

ethan on 2004-10-23T06:11:37

In my last entry I mumbled something about a tricky bug in perl that was allegedly unreportable. Good so because as it turned out, it wasn't a bug at all. I had this kind of setup:

    sub search {
	my ($self, $state) = @_;
	...
	# $state->{last_search} being an array-ref of previous
	# search patterns. You were supposed to cycle through them
	# with TAB 
	my $pattern = $self->get_input($state, $state->{last_search});
	...
	# once a list of matchings songs has been returned and the user
	# chose one of them to play
	$state->playlist->play;
    }

sub get_input { my ($self, $state, $searches) = @_; ... if ($hit_key == KEY_TAB) { push @$searches, shift @$searches; goto &search; } ... return $search_pattern; }


The above is naturally just a simplification. There are several event-loops going on at once so I kind of had to chose such an awkward way. Now the thing is that goto &func replaces the running instance of a function with &func. When looking at search() it becomes obvious that this would eventually expand to:

    my $pattern = $self->search($state);


which is wrong as now $pattern would contain the return value of search which would be its last value evaluated ($state->playlist->play always returns 1). Now I changed things so that get_input does a goto &get_input instead.

So far I always thought that goto &func would be one of those less harmful things. But in fact, it's even worse than anything Dijkstra described in his pamphlet.