an error I don't understand

Hi,

I am getting an error and don't know why it happens, it might even be a 
bug. It is about an assignment to a CStruct variable.

The structure is defined like;

class cairo_path_data_point_t is repr('CStruct') is export {
   has num64 $.x;
   has num64 $.y;

   submethod TWEAK ( :$native-object ) {
     $!x = $native-object.x;
     $!y = $native-object.y;
   }
}


The error is generated when typed variables are used (below, $x is also 
a cairo_path_data_point_t);

my cairo_path_data_point_t $p1 = $x;

or

my cairo_path_data_point_t $p1 = 
cairo_path_data_point_t.new(:native-object($x));

but not with

my cairo_path_data_point_t $p1 .= new(:native-object($x));

or

my $p1 = $x;

After which all fields in the structure are happely accessable using $p1!


The error is

Type check failed in assignment to $p1; expected cairo_path_data_point_t 
but got cairo_path_data_point_t.new(x => 0e0, y => 0e0)


Raku version: 2020.06-7-gf1960baa9 built on MoarVM version 
2020.06-6-gbf6af07de
implementing Raku 6.d.

The content of the structure does not matter, I've seen it with other 
structures too.

Regards,
Marcel
0
mt1957
6/27/2020 3:56:41 PM
perl.perl6.users 1425 articles. 0 followers. Follow

3 Replies
13 Views

Similar Articles

[PageSpeed] 23

--00000000000022de2c05a91437e1
Content-Type: text/plain; charset="UTF-8"

I don't know why you are getting an error.

But I think that this is one case where you should be writing `BUILD`
instead of `TWEAK`.
Note though that you can only have one `BUILD` or `TWEAK` per class.

---

Or maybe you want a multi method `new` instead?

    multi method new ( :$native-object! ) {
        samewith( x => $native-object.x, y => $native-object.y )
    }

Assuming that `x` and `y` are actually public attributes you could pull
them out of the object in the signature.

    multi method new ( :$native-object! (:$x, :$y) ) {
        samewith( :$x, :$y )
    }

If you need to throw out other public attributes, add `*%`

    multi method new ( :$native-object! (:$x, :$y, *%) ) {
        samewith( :$x, :$y )
    }

---

Honestly I do not understand why you are passing in an already constructed
object, and I don't know anything about it either.

If you gave us answers for those two questions, we may be able to help you
better.


On Sat, Jun 27, 2020 at 10:56 AM Marcel Timmerman <mt1957@gmail.com> wrote:

> Hi,
>
> I am getting an error and don't know why it happens, it might even be a
> bug. It is about an assignment to a CStruct variable.
>
> The structure is defined like;
>
> class cairo_path_data_point_t is repr('CStruct') is export {
>    has num64 $.x;
>    has num64 $.y;
>
>    submethod TWEAK ( :$native-object ) {
>      $!x = $native-object.x;
>      $!y = $native-object.y;
>    }
> }
>
>
> The error is generated when typed variables are used (below, $x is also
> a cairo_path_data_point_t);
>
> my cairo_path_data_point_t $p1 = $x;
>
> or
>
> my cairo_path_data_point_t $p1 =
> cairo_path_data_point_t.new(:native-object($x));
>
> but not with
>
> my cairo_path_data_point_t $p1 .= new(:native-object($x));
>
> or
>
> my $p1 = $x;
>
> After which all fields in the structure are happely accessable using $p1!
>
>
> The error is
>
> Type check failed in assignment to $p1; expected cairo_path_data_point_t
> but got cairo_path_data_point_t.new(x => 0e0, y => 0e0)
>
>
> Raku version: 2020.06-7-gf1960baa9 built on MoarVM version
> 2020.06-6-gbf6af07de
> implementing Raku 6.d.
>
> The content of the structure does not matter, I've seen it with other
> structures too.
>
> Regards,
> Marcel
>

--00000000000022de2c05a91437e1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I don&#39;t know why you are getting an error.<div><br></d=
iv><div>But I think that this is one case where you should be writing `BUIL=
D` instead of `TWEAK`.</div><div>Note though that you can only have one `BU=
ILD` or `TWEAK` per class.</div><div><br></div><div>---</div><div><br></div=
><div>Or maybe you want a multi method `new` instead?</div><div><br></div><=
div>=C2=A0 =C2=A0 multi method new ( :$native-object! ) {</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 samewith( x =3D&gt; $native-object.x, y =3D&gt; $nativ=
e-object.y )</div><div>=C2=A0 =C2=A0 }</div><div><br></div><div>Assuming th=
at `x` and `y` are actually public attributes you could pull them out of th=
e object in the signature.</div><div><br></div><div>=C2=A0 =C2=A0 multi met=
hod new ( :$native-object! (:$x, :$y) ) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 sa=
mewith( :$x, :$y )<br>=C2=A0 =C2=A0 }<br></div><div><br></div><div>If you n=
eed to throw out other public attributes, add `*%`</div><br>=C2=A0 =C2=A0 m=
ulti method new ( :$native-object! (:$x, :$y, *%) ) {<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 samewith( :$x, :$y )<br>=C2=A0 =C2=A0 }<div><br></div><div>---</=
div><div><br></div><div>Honestly I do not understand why you are passing in=
 an already constructed object, and I don&#39;t know anything about it eith=
er.</div><div><br></div><div>If you gave us answers for those two questions=
, we may be able to help you better.</div><div><br></div></div><br><div cla=
ss=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Jun 27, 20=
20 at 10:56 AM Marcel Timmerman &lt;<a href=3D"mailto:mt1957@gmail.com">mt1=
957@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi=
ng-left:1ex">Hi,<br>
<br>
I am getting an error and don&#39;t know why it happens, it might even be a=
 <br>
bug. It is about an assignment to a CStruct variable.<br>
<br>
The structure is defined like;<br>
<br>
class cairo_path_data_point_t is repr(&#39;CStruct&#39;) is export {<br>
=C2=A0=C2=A0 has num64 $.x;<br>
=C2=A0=C2=A0 has num64 $.y;<br>
<br>
=C2=A0=C2=A0 submethod TWEAK ( :$native-object ) {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 $!x =3D $native-object.x;<br>
=C2=A0=C2=A0=C2=A0=C2=A0 $!y =3D $native-object.y;<br>
=C2=A0=C2=A0 }<br>
}<br>
<br>
<br>
The error is generated when typed variables are used (below, $x is also <br=
>
a cairo_path_data_point_t);<br>
<br>
my cairo_path_data_point_t $p1 =3D $x;<br>
<br>
or<br>
<br>
my cairo_path_data_point_t $p1 =3D <br>
cairo_path_data_point_t.new(:native-object($x));<br>
<br>
but not with<br>
<br>
my cairo_path_data_point_t $p1 .=3D new(:native-object($x));<br>
<br>
or<br>
<br>
my $p1 =3D $x;<br>
<br>
After which all fields in the structure are happely accessable using $p1!<b=
r>
<br>
<br>
The error is<br>
<br>
Type check failed in assignment to $p1; expected cairo_path_data_point_t <b=
r>
but got cairo_path_data_point_t.new(x =3D&gt; 0e0, y =3D&gt; 0e0)<br>
<br>
<br>
Raku version: 2020.06-7-gf1960baa9 built on MoarVM version <br>
2020.06-6-gbf6af07de<br>
implementing Raku 6.d.<br>
<br>
The content of the structure does not matter, I&#39;ve seen it with other <=
br>
structures too.<br>
<br>
Regards,<br>
Marcel<br>
</blockquote></div>

--00000000000022de2c05a91437e1--
0
b2gills
6/27/2020 5:32:42 PM
--------------874D62013A3798CFFFC6E0D8
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Brad,

> I don't know why you are getting an error.
>
> But I think that this is one case where you should be writing `BUILD` 
> instead of `TWEAK`.
> Note though that you can only have one `BUILD` or `TWEAK` per class.
A quick test showed to me that it doesn't matter if I use BUILD or 
TWEAK. Besides this, I tried this construct before without the TWEAK or 
BUILD submethods and the assignment generated the same errors.

To answer your question below I just want to have an assignment to 
another typed variable which works for all variables but not the CStruct 
variable. Like below;

my cairo_path_data_point_t $p1 = $another-path-data-point;

I must also mention that it becomes awkward when such a variable is 
provided as an argument to some method. Binding will generate also such 
message.

In the mean time I made a small program which didn't generate errors, 
see below
---
use v6;
use NativeCall;

class cairo_path_data_point_t is repr('CStruct') is export {
   has num64 $.x;
   has num64 $.y;
}

my cairo_path_data_point_t $d1 .= new( :x(1e0), :y(2e0));
my cairo_path_data_point_t $d2 = $d1;

note "d2: ", $d2.perl;            # d2: cairo_path_data_point_t.new(x => 
1e0, y => 2e0)
---

and this is what I want.... I now need a Crystal Ball to find me the 
answer of the problems I ran into :-\

Well, at least the error is weird to warn me that I cannot assign a 
variable to another of the same type.

Regards,
Marcel
>
> ---
>
> Or maybe you want a multi method `new` instead?
>
>     multi method new ( :$native-object! ) {
>         samewith( x => $native-object.x, y => $native-object.y )
>     }
>
> Assuming that `x` and `y` are actually public attributes you could 
> pull them out of the object in the signature.
>
>     multi method new ( :$native-object! (:$x, :$y) ) {
>         samewith( :$x, :$y )
>     }
>
> If you need to throw out other public attributes, add `*%`
>
>     multi method new ( :$native-object! (:$x, :$y, *%) ) {
>         samewith( :$x, :$y )
>     }
>
> ---
>
> Honestly I do not understand why you are passing in an already 
> constructed object, and I don't know anything about it either.
>
> If you gave us answers for those two questions, we may be able to help 
> you better.
>
>
> On Sat, Jun 27, 2020 at 10:56 AM Marcel Timmerman <mt1957@gmail.com 
> <mailto:mt1957@gmail.com>> wrote:
>
>     Hi,
>
>     I am getting an error and don't know why it happens, it might even
>     be a
>     bug. It is about an assignment to a CStruct variable.
>
>     The structure is defined like;
>
>     class cairo_path_data_point_t is repr('CStruct') is export {
>        has num64 $.x;
>        has num64 $.y;
>
>        submethod TWEAK ( :$native-object ) {
>          $!x = $native-object.x;
>          $!y = $native-object.y;
>        }
>     }
>
>
>     The error is generated when typed variables are used (below, $x is
>     also
>     a cairo_path_data_point_t);
>
>     my cairo_path_data_point_t $p1 = $x;
>
>     or
>
>     my cairo_path_data_point_t $p1 =
>     cairo_path_data_point_t.new(:native-object($x));
>
>     but not with
>
>     my cairo_path_data_point_t $p1 .= new(:native-object($x));
>
>     or
>
>     my $p1 = $x;
>
>     After which all fields in the structure are happely accessable
>     using $p1!
>
>
>     The error is
>
>     Type check failed in assignment to $p1; expected
>     cairo_path_data_point_t
>     but got cairo_path_data_point_t.new(x => 0e0, y => 0e0)
>
>
>     Raku version: 2020.06-7-gf1960baa9 built on MoarVM version
>     2020.06-6-gbf6af07de
>     implementing Raku 6.d.
>
>     The content of the structure does not matter, I've seen it with other
>     structures too.
>
>     Regards,
>     Marcel
>


--------------874D62013A3798CFFFC6E0D8
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Hi Brad,<br>
      <br>
    </div>
    <blockquote type="cite"
cite="mid:CAD2L-T3J1cu9UYsQhNtS+X5kVFqSrmPQYnXshqRB+29-4hA8nQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">I don't know why you are getting an error.
        <div><br>
        </div>
        <div>But I think that this is one case where you should be
          writing `BUILD` instead of `TWEAK`.</div>
        <div>Note though that you can only have one `BUILD` or `TWEAK`
          per class.</div>
      </div>
    </blockquote>
    A quick test showed to me that it doesn't matter if I use BUILD or
    TWEAK. Besides this, I tried this construct before without the TWEAK
    or BUILD submethods and the assignment generated the same errors.<br>
    <br>
    To answer your question below I just want to have an assignment to
    another typed variable which works for all variables but not the
    CStruct variable. Like below;<br>
    <br>
    my cairo_path_data_point_t $p1 = $another-path-data-point;<br>
    <br>
    I must also mention that it becomes awkward when such a variable is
    provided as an argument to some method. Binding will generate also
    such message.<br>
    <br>
    In the mean time I made a small program which didn't generate
    errors, see below<br>
    ---<br>
    use v6;<br>
    use NativeCall;<br>
    <br>
    class cairo_path_data_point_t is repr('CStruct') is export {<br>
      has num64 $.x;<br>
      has num64 $.y;<br>
    }<br>
    <br>
    my cairo_path_data_point_t $d1 .= new( :x(1e0), :y(2e0));<br>
    my cairo_path_data_point_t $d2 = $d1;<br>
    <br>
    note "d2: ", $d2.perl;            # d2:
    cairo_path_data_point_t.new(x =&gt; 1e0, y =&gt; 2e0)<br>
    ---<br>
    <br>
    and this is what I want.... I now need a Crystal Ball to find me the
    answer of the problems I ran into :-\<br>
    <br>
    Well, at least the error is weird to warn me that I cannot assign a
    variable to another of the same type.<br>
    <br>
    Regards,<br>
    Marcel<br>
    <blockquote type="cite"
cite="mid:CAD2L-T3J1cu9UYsQhNtS+X5kVFqSrmPQYnXshqRB+29-4hA8nQ@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <div>---</div>
        <div><br>
        </div>
        <div>Or maybe you want a multi method `new` instead?</div>
        <div><br>
        </div>
        <div>    multi method new ( :$native-object! ) {</div>
        <div>        samewith( x =&gt; $native-object.x, y =&gt;
          $native-object.y )</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>Assuming that `x` and `y` are actually public attributes
          you could pull them out of the object in the signature.</div>
        <div><br>
        </div>
        <div>    multi method new ( :$native-object! (:$x, :$y) ) {<br>
                  samewith( :$x, :$y )<br>
              }<br>
        </div>
        <div><br>
        </div>
        <div>If you need to throw out other public attributes, add `*%`</div>
        <br>
            multi method new ( :$native-object! (:$x, :$y, *%) ) {<br>
                samewith( :$x, :$y )<br>
            }
        <div><br>
        </div>
        <div>---</div>
        <div><br>
        </div>
        <div>Honestly I do not understand why you are passing in an
          already constructed object, and I don't know anything about it
          either.</div>
        <div><br>
        </div>
        <div>If you gave us answers for those two questions, we may be
          able to help you better.</div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sat, Jun 27, 2020 at 10:56
          AM Marcel Timmerman &lt;<a href="mailto:mt1957@gmail.com"
            moz-do-not-send="true">mt1957@gmail.com</a>&gt; wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
          <br>
          I am getting an error and don't know why it happens, it might
          even be a <br>
          bug. It is about an assignment to a CStruct variable.<br>
          <br>
          The structure is defined like;<br>
          <br>
          class cairo_path_data_point_t is repr('CStruct') is export {<br>
             has num64 $.x;<br>
             has num64 $.y;<br>
          <br>
             submethod TWEAK ( :$native-object ) {<br>
               $!x = $native-object.x;<br>
               $!y = $native-object.y;<br>
             }<br>
          }<br>
          <br>
          <br>
          The error is generated when typed variables are used (below,
          $x is also <br>
          a cairo_path_data_point_t);<br>
          <br>
          my cairo_path_data_point_t $p1 = $x;<br>
          <br>
          or<br>
          <br>
          my cairo_path_data_point_t $p1 = <br>
          cairo_path_data_point_t.new(:native-object($x));<br>
          <br>
          but not with<br>
          <br>
          my cairo_path_data_point_t $p1 .= new(:native-object($x));<br>
          <br>
          or<br>
          <br>
          my $p1 = $x;<br>
          <br>
          After which all fields in the structure are happely accessable
          using $p1!<br>
          <br>
          <br>
          The error is<br>
          <br>
          Type check failed in assignment to $p1; expected
          cairo_path_data_point_t <br>
          but got cairo_path_data_point_t.new(x =&gt; 0e0, y =&gt; 0e0)<br>
          <br>
          <br>
          Raku version: 2020.06-7-gf1960baa9 built on MoarVM version <br>
          2020.06-6-gbf6af07de<br>
          implementing Raku 6.d.<br>
          <br>
          The content of the structure does not matter, I've seen it
          with other <br>
          structures too.<br>
          <br>
          Regards,<br>
          Marcel<br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------874D62013A3798CFFFC6E0D8--
0
mt1957
6/27/2020 6:05:12 PM
Solved!

It had something to do with having an installed version and testing a 
program using a partly changed local version (renames of files too) and 
partly the installed version. This caused the same type from several 
sources and thereby making them differ. Removing the installed versions 
cleared every error.

That leaves us with the error message not completely comprehensible by 
people like me. Raku does see a difference but doesn't say which.

Anyways, thanks for answering
Marcel
0
mt1957
7/1/2020 7:50:20 AM
Reply: