[chuck-dev] fixed array compatibility checking (PATCH)
Robin Haberkorn
robin.haberkorn at googlemail.com
Wed Sep 5 21:29:48 EDT 2012
Hi!
Here's another minor bug fix.
Consider this example:
UGen @osc[2];
new SinOsc @=> osc[0];
new PulseOsc @=> osc[1];
It will work because the type checker will consider SinOsc/PulseOsc and
UGen compatible for assignment (using the "isa" function which in turn
is using the <= operator). This is because Chuck_Type "<=" will check
that SinOsc is a child of UGen.
However, unintuitively you cannot use the array constructor:
[new SinOsc, new PulseOsc] @=> UGen @osc[];
Since the left-hand-side type (Osc[] in this case) is not considered
compatible to UGen[]. Neither are they directly the same nor are they
descended.
That's because "<=" does not check for the arrays' "actual" types (Osc
and UGen) being compatible.
You must either declare the "osc" variable with the same type as the
constructed array:
[new SinOsc, new PulseOsc] @=> Osc @osc[];
or you have to cast the array members to UGen so the lhs type is
(predictably) UGen[]:
[new SinOsc $ UGen, new PulseOsc $ UGen] @=> UGen @osc[];
Both options are not very intuitive for the user. The "Osc" class/type
is not even documented I think. Not to mention that it's not always easy
to guess the type of a constructed Object array.
The attached patch fixes that by allowing arrays of the same depth and
derived "actual" types being considered compatible.
I think this is the last array patch for the time being, though I'm
tempted to implement support for map keys in the inline array
constructor :-).
Best regards,
Robin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-array-compatibility-checking.patch
Type: text/x-patch
Size: 936 bytes
Desc: not available
URL: <http://lists.cs.princeton.edu/pipermail/chuck-dev/attachments/20120906/33f2be8d/attachment.bin>
More information about the chuck-dev
mailing list