Overridden defaulted arguments don't get set

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Overridden defaulted arguments don't get set

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Wed Mar 14, 2018 11:36 am

OK, that's what I wanted to hear. It seems I missed some case when checking this.
I'll have a look later this evening.

Re: Overridden defaulted arguments don't get set

by ZippeyKeys12 » Wed Mar 14, 2018 9:45 am

The warning is obviously intentional, the problem is that it gives an insufficient arguments error when a function call omits arguments that have defaults in gzdoom.pk3.
Also, I'm using whatever was the latest devbuild yesterday.

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Wed Mar 14, 2018 7:46 am

That warning is fully intentional. Specifying defaults for an override should not be possible and in ZScript 3.3 will error out.
The main problem here is that the missing parameters get filled in by the called function so leaving out some arguments where the defaults differ would create unpredictable behavior because the default arguments that get set depend on the actual class type and not the calling pointer type. As a consequence these defaults will get ignored now and a warning emitted in older ZScript versions, and an error in the new one.
If that is all you get for the two different scripts, all works as intended.

Re: Overridden defaulted arguments don't get set

by _mental_ » Wed Mar 14, 2018 7:11 am

Unfortunately it doesn't work with the latest code at the moment.
It's a bit different issue though: default values are ignored when virtual function is overridden.

The working sample gives the following warning

Code: Select all

:zscript.txt, line 5: Default values for parameter of virtual override will be ignored!

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Wed Mar 14, 2018 1:56 am

Can you retest this with the latest devbuild?

Re: Overridden defaulted arguments don't get set

by ZippeyKeys12 » Tue Mar 13, 2018 6:18 pm

This might be the same error, marrub's appears to occur in game while mine occurs during loading.
Spoiler: Working Code
Spoiler: Error
And the error code gives me:

Code: Select all

Script error, "aaa.zip:zscript.zsc" line 11:
Insufficient arguments in call to DamageMobj

Re: Overridden defaulted arguments don't get set

by _mental_ » Thu Mar 01, 2018 9:28 am

Yes, it's just one relatively small change.

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Thu Mar 01, 2018 9:07 am

Is that branch complete?

Re: Overridden defaulted arguments don't get set

by drfrag » Thu Mar 01, 2018 9:04 am

And checking the solution to the cvar protection compatibility issues by _mental_ (cvar_safe_value branch).

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Thu Mar 01, 2018 8:03 am

Quick note: This is the last one that needs fixing before preparing a new release.

Re: Overridden defaulted arguments don't get set

by Graf Zahl » Sat Jan 27, 2018 3:35 pm

The latter one is a completely unrelated issue. Apparently the modifier flags are not checked properly when comparing signatures.

Re: Overridden defaulted arguments don't get set

by Marrub » Sat Jan 27, 2018 3:22 pm

_mental_ wrote:I added the following code to ZombieMan class and it works fine

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags, double angle)
{
	return super.DamageMobj(inflictor, source, damage, mod, flags, angle);
}
Please post a complete runnable sample.
Sorry, I should have been more specific, it crashes when you call DamageMobj with omitted parameters. The only place in the source that I know of that does this is A_VileAttack, which if you get hit by it as a player, will crash.

Also a related issue, not sure if it needs its own thread: Omitting parameter attributes will cause other weird buginess, including crashing, but not emit a warning or error.
For instance, the override signature in an Inventory-derived class:

Code: Select all

override bool TryPickup(Actor mo)
will cause crashing if, for instance, this is done:

Code: Select all

if(mo is "PlayerPawn") return true;
However, of course, the correct function signature works fine:

Code: Select all

override bool TryPickup(in out Actor mo)

Re: Overridden defaulted arguments don't get set

by _mental_ » Sat Jan 27, 2018 2:46 pm

I added the following code to ZombieMan class and it works fine

Code: Select all

override int DamageMobj(Actor inflictor, Actor source, int damage, name mod, int flags, double angle)
{
	return super.DamageMobj(inflictor, source, damage, mod, flags, angle);
}
Please post a complete runnable sample.

Re: Overridden defaulted arguments don't get set

by Marrub » Sat Jan 27, 2018 1:05 pm

The issue is that if you don't have them in the override signature it will crash, not that there are defaultable arguments.

Re: Overridden defaulted arguments don't get set

by XxMiltenXx » Sat Jan 27, 2018 12:31 pm

I think this is intentional, as these are the default values that get used if those variables aren't passed when the function is called and you have to override the function first as it was originally written.

I think to have those filled automatically is rather a "feature" then, rather than a bug.

Top