[chuck-users] what have I stumbled upon this time?

Michael Heuer heuermh at gmail.com
Thu Mar 15 23:30:39 EDT 2012


Hello ChucKers,

Has anyone ever seen the value of a method parameter change based on
the value of some other method parameter?

The following class, when run after the LiCK library has been loaded,

public class MethodNameBug
{
  fun void methodName(int intValue)
  {
    <<<"methodName(int)",intValue>>>;
  }

  fun void methodName(float floatValue)
  {
    <<<"methodName(float)",floatValue>>>;
  }

  fun void methodName(int intValue, dur duration, Interpolation interpolation)
  {
    <<<"methodName(int, dur, Interpolation)",intValue,duration,interpolation>>>;
  }
}

MethodNameBug bug;

bug.methodName(60);
bug.methodName(2.0);

CubicIn cubicIn;
bug.methodName(60, 1::minute, cubicIn);

2::second => now;

results in

"LiCK imported." : (string)
[chuck](VM): sporking incoming shred: 1 (MethodNameBug.ck)...
methodName(int) 60
methodName(float) 2.000000
methodName(int, dur, Interpolation) 1078853632 2646000.000000 0x4eef80

Somehow the int value 60 passed in as intValue parameter is
interpreted as 1078853632 in the methodName(int, dur, Interpolation)
method call.

Now here's where it gets odd.  CubicIn is a LiCK class that extends
from Interpolation, and Interpolation extends FloatFunction, all short
functor-style classes

CubicIn.ck:
public class CubicIn extends Interpolation
{
    fun float evaluate(float value)
    {
        return Math.pow(value, 3.0);
    }
}

Interpolation.ck:
public class Interpolation extends FloatFunction
{
    // empty
}

FloatFunction.ck:
public class FloatFunction
{
    0.0 => float default;

    fun float evaluate(float value)
    {
        return default;
    }
}


If instead I instantiate and pass an interpolation instead

Interpolation interpolation;
bug.methodName(60, 1::minute, interpolation);

it works.

"LiCK imported." : (string)
[chuck](VM): sporking incoming shred: 1 (MethodNameBug.ck)...
methodName(int) 60
methodName(float) 2.000000
methodName(int, dur, Interpolation) 60 2646000.000000 0x69dfe0


Changing the method signature to accept an Object, or a string, or
another primitive value also works.

Object object;
bug.methodName(60, 1::minute, object);

methodName(int, dur, object) 60 2646000.000000 0x110b830


bug.methodName(60, 1::minute, "message");

methodName(int, dur, string) 60 2646000.000000 message


bug.methodName(60, 1::minute, 42);

methodName(int, dur, int) 60 2646000.000000 42


I have a special set of swear words reserved for ChucK, and I'm afraid
I've use them all up by this point.  Any ideas?

   michael


More information about the chuck-users mailing list