Raku / problem-solving

🦋 Problem Solving, a repo for handling problems that require review, deliberation and possibly debate
Artistic License 2.0
70 stars 16 forks source link

dd does not show coercion type on scalars #415

Closed librasteve closed 11 months ago

librasteve commented 11 months ago

this dd shows the Array(Any) coercion type: dd my Array() @b = [7] #Array[Array(Any)] @b = Array[Array(Any)].new($[7])

however,

this dd does not show the coercion part dd my Array() $c = [7] #Array $c = $[7]

I believe that we should have (for Scalars): dd my Array() $c = [7] #Array(Any) $c = $[7]

and, of course, it is then different to the baseline dd my Array $c = [7] #Array $c = $[7]

lizmat commented 11 months ago

I think this is really a Rakudo issue.

Also, I don't think this is dd's fault: It basically shows:

my Array() $c = [7];
say $c.WHAT.^name;  # Array

So it would seem to me that the .name introspection on coercion types is incomplete. pinging @vrurg

vrurg commented 11 months ago

So it would seem to me that the .name introspection on coercion types is incomplete. pinging

Why? .name doesn't have to have this information because it refers to the content of the scalar. The content either a concrete Array, or a type object. The type object could be a coercion, but the semantic of my Array() $c is expressed as "I want an array in this variable" and to me, for undefined cases, it means 'Array typeobject'. So, I'd be rather surprised finding a coercion there.

Moreover, most of the time coercion is not a subject for direct action. It is more like meta-info attached to certain language constructs to help it understand how to deal with incoming data. From this aspect the container is one of these constructs. And if we introspect it we'd find out that $c.VAR.of.^name is actually Array(Any), no matter if the value itself is concrete or not. Respectively, since dd is reporting it as Array $c = ..., i.e. as a variable, it must report the full type of the container.

My bottom line would be that it's not a problem-solving issue but a bug of Rakudo implementation. As such it either worth a new issue in Rakudo repository or transferring this one over there, if it's technically possible. The fix itself should be trivial.

librasteve commented 11 months ago

ok - so this is an issue with dd then... right?

what we have:

dd my Array() $c = [7];   #Array $c = $[7]   via    $c.^name

what I suggest:

dd my Array() $c = [7];   #Array(Any) $c = $[7]   via    $c.VAR.of

imvho this is not a raku bug, nor is it a dd bug, rather it is a feature request on dd [ie "please can we see the presence of a coercion type when we dd something"]

happy to move this issue where it can do most good

lizmat commented 11 months ago

Issue can not be moved, sadly, so closing here. A fix should be forthcoming.

lizmat commented 11 months ago

https://github.com/rakudo/rakudo/commit/57bda882dc is the fix