[chuck-dev] fixed array compatibility checking (PATCH)
robin.haberkorn at googlemail.com
Wed Sep 5 21:29:48 EDT 2012
Here's another minor bug fix.
Consider this example:
new SinOsc @=> osc;
new PulseOsc @=> osc;
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
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
[new SinOsc, new PulseOsc] @=> Osc @osc;
or you have to cast the array members to UGen so the lhs type is
[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
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 936 bytes
Desc: not available
More information about the chuck-dev