petdance/scratch — Issue #1363: tailcall to Class.new fails with overriden init
Author: petdance
Created: 2011-11-01 05:40:03+00:00
State: open
Labels: bug, core, Pri-normal, Sev-medium

Looking at winxed issue 7 in github:
https://github.com/NotFound/winxed/issues/7

I've found that the problem lies in parrot, as this pure pir code shows:
{{{
.namespace ['Foo']

.sub 'init' :method :vtable
say 'Foo.init'
.end

.sub 'init_pmc' :method :vtable
.param pmc value
say 'Foo.init'
.end

.sub hello :method
say 'Foo.hello'
.end

.sub attrs1
.param pmc clazz
say 'attrs1'
.local pmc at
at = clazz.'attributes'()
.return(at)
.end

.sub attrs2
.param pmc clazz
say 'attrs2'
.tailcall clazz.'attributes'()
.end

.sub newinstance1
.param pmc clazz
say 'newinstance1'
.local pmc instance
instance = clazz.'new'()
.return(instance)
.end

.sub newinstance2
.param pmc clazz
say 'newinstance2'
.tailcall clazz.'new'()
.end

.sub main :main
.local pmc clazz, at1, at2, instance1, instance2
newclass clazz, ['Foo']
addattribute clazz, 'bar'

null at1
at1 = attrs1(clazz)
at1 = at1['bar']
at1 = at1['name']
say at1
null instance1
instance1 = newinstance1(clazz)
instance1.'hello'()

null at2
at2 = attrs2(clazz)
at2 = at2['bar']
at2 = at2['name']
say at2
null instance2
instance2 = newinstance2(clazz)
instance2.'hello'()

.end
}}}
Tailcall to other method in Class (attributes in this example) works, but tailcall to new fails, it gets null instead of the newly created instance.

If the class does not override the 'init' vtable, it works.

The same happens with init_pmc tailcalling new with non empty argument list.

Originally http://trac.parrot.org/parrot/ticket/2193