ccrma / chuck

ChucK Music Programming Language
http://chuck.stanford.edu/
GNU General Public License v2.0
803 stars 128 forks source link

overzealous out of order decl compiler error #376

Closed gewang closed 9 months ago

gewang commented 11 months ago

encountering compiler error

iss-out-of-order.ck:6:13: error: variable/member 'a' is used before declaration
[6]         <<< a >>>;
                ^
iss-out-of-order.ck: ...in function 'void Foo.go()'

in the following program:

class Foo
{
    fun void go()
    {
        // this shouldn't produce an error, but does
        <<< a >>>;
    }
}

// decl and init
5 => int a;

possible problem: overzealous checking of decl order possible remedy: should handle global usage and func/classdef usage of a differently

gewang commented 10 months ago

another example

public class Foo
{
    BarFactory.make() @=> Bar bar;
}

class Bar
{
    "i am bar" => string name;
}

class BarChild extends Bar
{
    "i extend bar" => name;
}

class BarFactory
{
    fun static BarChild make()
    {
        return new BarChild;
    }
}
gewang commented 9 months ago

addressed in dbcec841135bd9f24c7357ccfb1f50c542443c4b and b6206584314c1b8237264eddb82c85858fcf0698, included in 1.5.2.0