[Vala] Scoping error in public constant members



Jurg,

        I have found another unexpected error.  The following code works correctly if Error3a and Error3b are in the same file, but if you separate them into different files, the vala compiler will compile them properly, however the C compilation step will complain about  ERROR3_CONSTANT_HOLDER1_X not being defined in the second file.  Looking at the C code generated by vala, you have defined public const variables as being static variables in the resulting C file, thus it's scope is not visible outside the c file.   Perhaps instead of being static, they should be global variables and declared as extern in the resulting c header file.  The current method would still be appropriate for private const variables.

using GLib;

// Error 3a
namespace Error3 {

        public class ConstantHolder1 {
                public const int X = 256;
        }
}

// Error 3b
namespace Error3 {

        public class ConstantHolder2 {
                public const int X = 500;
        }

        public class ConstantTest {

                public void print() {
                        stdout.printf("X = %d\n",Error3.ConstantHolder1.X );
                        stdout.printf("Y = %d\n",Error3.ConstantHolder2.X);
                }

        }

        static int main(string[] args) {
                ConstantTest ct = new ConstantTest();
                ct.print();
        }
}

Again, keep up the good work.  Hope this helps with your development.

Cayle



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]