ZScript ignores expressions on left side of a static call

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

ZScript ignores expressions on left side of a static call

Post by Gutawer »

Example code:

Code: Select all

class T {
    int mem;
    T modify() {
        mem += 1;
        return self;
    }
    static void doit() {
        Console.printf("hi");
    }
}
class Whatever : Actor {
    override void tick() {
        let x = new("T");
        x.modify().doit();
        Console.printf("%d", x.mem);
    }
}
Expected behaviour here is that hi and then 1 is printed, but because doit is a static function, it doesn't require a self pointer, and therefore x.modify() never has code emitted. So it prints hi and then 0 instead.
Another example is that:

Code: Select all

T x = NULL;
x.doit();
Causes no null pointer problems, because x never gets null checked - although this case is more debatable since languages like Java behave the same here.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49184
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript ignores expressions on left side of a static cal

Post by Graf Zahl »

How about "Don't do that?" I'd consider that undefined behavior in the best of cases. The problem here is that the expression gets thrown out long before it gets evaluated
User avatar
Gutawer
Posts: 469
Joined: Sat Apr 16, 2016 6:01 am
Preferred Pronouns: She/Her

Re: ZScript ignores expressions on left side of a static cal

Post by Gutawer »

I completely agree, but in that case, shouldn't it be a compiler error? That's precedented by languages like C#, which only allow calling of static methods using the type name, apart from the one exception of calling it without any prefix (i.e. doSomething() instead of self.doSomething()).

Return to “Bugs [GZDoom]”