Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Composing an inherited class through a parametric role doesn't work in Rakudo #2679

Open p6rt opened 12 years ago

p6rt commented 12 years ago

Migrated from rt.perl.org#111912 (status was 'open')

Searchable as RT111912$

p6rt commented 12 years ago

From @masak

\ nom​: role A[​::T $] { also is T }; class B { }; class C does A[B] { }; say C ~~ B \ rakudo 1a468d​: OUTPUT«===SORRY!===␤Cannot type check against type variable T␤» \ that's... somwhere between LTA and wrong, I'm not sure where exactly it is :-) * masak submits rakudobug

p6rt commented 7 years ago

From @smls

On Wed, 21 Mar 2012 08​:32​:55 -0700, masak wrote​:

\ nom​: role A[​::T $] { also is T }; class B { }; class C does A[B] { }; say C ~~ B \ rakudo 1a468d​: OUTPUT«===SORRY!===␤Cannot type check against type variable T␤»

Now it throws earlier, and with a nicer error message​:

  ===SORRY!=== Error while compiling -e   T does not support inheritance, so A cannot inherit from it

Not sure if it can be made to work like you wanted.

Not sure if it can be made to actually work (i.e. defer the `also is T` until class composition time, at which point the concrete type of T would be available).

Seems related to​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=130634

p6rt commented 7 years ago

The RT System itself - Status changed from 'new' to 'open'

usev6 commented 1 year ago

It looks like this works now as expected:

$ ./rakudo-m -e 'role A[::T $] { also is T }; class B {}; class C does A[B] {}; say C ~~ B'
True

Tagging "testneeded".

masak commented 12 months ago

I'm actually a little bit shocked that this works. My mental model needs to do some stretching exercises before attempting to cover a semantics where this Just Works. I'm now very curious, and might dip into the implementation just to see what's going on. (Note message from smls in 2017, "Not sure if it can be made to work like you wanted.")

Is it the case that the role body contains a... "script" (with possibly-late-bound things like T) which executes on role composition (after substituting B into T)? That's the only way I can imagine this working at all.

usev6 commented 12 months ago

For the record -- and maybe helpful if you want to look at the implementation: According to bisectable6 (https://colabti.org/irclogger/irclogger_log/raku-dev?date=2023-10-08#l10) the behavior changed (from dying with T does not support inheritance, so A cannot inherit from it to printing True) with commit https://github.com/rakudo/rakudo/commit/4b99656875.

masak commented 12 months ago

That is indeed helpful. Thank you! I can't say I follow the diff perfectly, but the commit message indeed settles whether this was a deliberate move or not.