rakudo / rakudo

🦋 Rakudo – Raku on MoarVM, JVM, and JS
https://rakudo.org/
Artistic License 2.0
1.73k stars 374 forks source link

Self-referential struct does not work with CArray[Pointer[]] declaration. #3264

Closed Xliff closed 2 weeks ago

Xliff commented 5 years ago

The Problem

When attempting to define a self-referential structure from C, I ran into the following error:

    ===SORRY!===
    Cannot resolve caller ACCEPTS(Bool:U: GIO::DBus::Raw::Types::GDBusAnnotationInfo); none of these signatures match:
        (Bool:D: Mu \topic, *%_)
        (Bool:U: \topic, *%_)
Stage start      :   0.000

This stems from the fact that it appears that CArray[] and Pointer[] do not see the self-referential nature of the declaration. Here is a small sample that exposes this issue:

use NativeCall; 
class A is repr<CStruct> { 
  has uint32 $.a; 
  has CArray[Pointer[A]] $.aa; 
};

Note that this does work, possibly due to special case handling:

class A is repr<CStruct> { 
  has uint32 $.a; 
  has A $.aa; 
};

Expected Behavior

Actual Behavior

Steps to Reproduce

Environment

Kaiepi commented 5 years ago

I think the issue's that CArray.^parameterize and Pointer.^parameterize take a parameter of type Mu:U, but use routines that expect it to be of type Any. Parameterizations with [] happen at compile-time, and when it happens in your example, the class hasn't been composed yet, so it fails the type check for Any when it wouldn't otherwise. Writing the parameterization methods to only use routines that work with Mu fixes the error for me.

Xliff commented 5 years ago

@Kaiepi++ ... Have you run this solution through Roast? If not, I'd be willing.

Kaiepi commented 5 years ago

I'm in the middle of running make spectest for other changes, so I can't right now. I can make a PR for what I have so you can though.