# New Ticket Created by  Itsuki Toyota 
# Please include the string:  [perl #129831]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129831 >


See the following results:

* codes *

t/03-role.c
----------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "03-role.h"

#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT extern
#endif

struct Foo {
  int a;
  double b;
} Foo;


void c_insert(struct Foo* foo, void* item) {
  // insert operation
}
----------------------------



t/03-role.h
----------------------------
#if ! defined(HEADER_ROLE_H)
#define HEADER_ROLE_H

#ifdef __cplusplus
extern "C" {
#endif

struct Foo;
void c_insert(struct Foo*, void*);

#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif

#endif /* HEADER_ROLE_H */
----------------------------



t/03-role.t
----------------------------
use v6;
use Test;
use NativeCall;
use lib <lib t>;
use CompileTestLib;

compile_test_lib('03-role');

role Foo is export is repr('CPointer') {
    my sub c_insert(Foo, Pointer[void] is rw) is native("./03-callback") { * }
    
    method insert(Pointer[void] $item) {
        c_insert(self, $item);
    }
}

done-testing;
----------------------------

* results *
----------------------------


$ mi6 test t/03-role.t
==> Set PERL6LIB=/home/itoyota/Programs/p6-Foo/lib
==> prove -e /home/itoyota/.rakudobrew/bin/../moar-nom/install/bin/perl6 -r 
t/03-role.t
t/03-role.t .. ===SORRY!=== Error while compiling 
/home/itoyota/Programs/p6-Foo/t/03-role.t
Too many positionals passed; expected 2 arguments but got 3
at /home/itoyota/Programs/p6-Foo/t/03-role.t:10
t/03-role.t .. Dubious, test returned 1 (wstat 256, 0x100)
No subtests run 

Test Summary Report
-------------------
t/03-role.t (Wstat: 256 Tests: 0 Failed: 0)
  Non-zero exit status: 1
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  1 wallclock secs ( 0.02 usr  0.00 sys +  0.40 cusr  0.02 
csys =  0.44 CPU)
Result: FAIL

----------------------------



It seems weird to me, because roles can define with `is export is 
repr("CPointer")` traits and can use `self`.without any errors as the following 
example.

$ perl6 -MNativeCall -e 'role R is export is repr("CPointer") { method 
insert($item) { self!c_insert(self, $item); }; method !c_insert(R $r, $item){ 
say $r; } }; my $r = R.new; $r.insert(10);'
R.new 


My Perl 6 version is:
$ perl6 --version
This is Rakudo version 2016.09-105-g4abc28c built on MoarVM version 
2016.09-13-g34c375a
implementing Perl 6.c.

Reply via email to