soul-lang / SOUL

The SOUL programming language and API
Other
1.71k stars 95 forks source link

Arithmetic functions only work with const variables #12

Closed SilvinWillemsen closed 4 years ago

SilvinWillemsen commented 4 years ago

Hi there!

I am having some issues with performing arithmetic functions on non-const variables.

    let a = 10.0f;
    let sqrtTest1 = sqrt(a);  // OK: a is constant
    let powTest1 = pow(a, 2); // OK: a is constant

    var b = 20.0f;
    let sqrtTest2 = sqrt(b);  // error: Found an expression when expecting a constant
    let powTest2 = pow(b, 2); // error: Found an expression when expecting a constant

    const float c = 30.0f;
    let sqrtTest3 = sqrt(c);  // OK: c is constant
    let powTest3 = pow(c, 2); // OK: c is constant

I only tested this with sqrt() and pow(), but I suppose the same goes for other arithmetic functions. Is this done on purpose?

Thanks in advance!

julianstorer commented 4 years ago

We've rewritten that bit of the compiler in the last few days! (new version should be out in the next few days)

Trying your code with the new version, it'll work fine, except that you still need to make the argument types match - i.e. instead of 2 you need to use 2.0f since an int can't be silently converted to a float32. But otherwise, this'll be fixed!

What you were seeing here with constants was just that the compiler was being lenient about allowing a 2 to get silently cast to float because it knows that 2 is a case where no precision is lost.