Evil Source Filter Bugs

Ovid on 2004-09-28T20:23:21

It's a long story, but the difficult-to-find bug that I mentioned earlier was caused by a source filter that created a forward sub declaration for a sub that had been commented out. This breaks inheritance:

#!/usr/local/bin/perl
package ClassA;
sub new { bless {}, shift }
sub test { 'ClassA::test' }

package ClassB;
@ClassB::ISA = 'ClassA';
sub test;

package main;
use Test::More 'no_plan';

ok(!defined *ClassB::new{CODE}, 
    '&Class::new is not defined because it is inherited');
ok(defined *ClassB::test{CODE}, 
    '&ClassB::test should be defined because there is a prototype');
is(ClassB->new->test, 'ClassA::test', 
    '... but this test says it is not');


Department of Redundancies Department

VSarkiss on 2004-09-29T14:48:52

Evil / Source Filter / Bugs
Aren't those all the same?

;-)
I wish I could put one of those "Fan" smileys in here, but Slash won't allow <img> tags....

Re:Department of Redundancies Department

Aristotle on 2004-09-29T18:31:09

Yeah, what he said. Don't use source filters. Period. If you can fiddle things using the optree, great, do that. It's much, much harder to write the code, but you actually have a chance at making it work reliably. If you let source filters loose on your code on the other hand, all bets are off.

Source filters are fun to play with, but there's no place for them in production code. Even the preprocessor in C is less evil (though not by all that much; cf. Lisp macros).

Re:Department of Redundancies Department

Ovid on 2004-09-29T18:39:49

Regrettably, I don't believe I could fiddle with the op codes because much of what I want to do won't actually compile in Perl.

Re:Department of Redundancies Department

btilly on 2004-09-30T14:46:11

...much of what I want to do won't actually compile in Perl.

I'd take that as a sign that possibly your desires should be changed. :-P

Ben