polserver/testsuite/escript/classes/method-default-args-new.src
Kevin Eady a953a37fa7 Support function reference calls with default parameters (#710)
* Support default args in funcref calls
- Simplify BFunctionRef by using funcref index
- Emit default args when visiting function reference

* Move default args gen to second-pass visit

* Better error message on param count errors

* Check for constructor in MTH_NEW

* Address self-review comments
- Update code comments

* Introduce ResourceManager to pol testsuite
- Create a new class-based resource manager for deleting resources
(item NPCs, multis) after each test.
- Migrate house_set_multiid test to use new ResourceManager.

* Move resource cleanup
2024-10-10 18:06:04 +02:00

70 lines
2.1 KiB
Text

// Test MTH_NEW calls with default args and variadic args
class ClassA()
function ClassA( this, arg0 )
this.arg0 := arg0;
endfunction
function stringify( this )
return $"ClassA::stringify this={this} this.arg0={this.arg0}";
endfunction
endclass
class ClassB()
function ClassB( this, arg0, arg1 := "default.a1" )
this.arg0 := arg0;
this.arg1 := arg1;
endfunction
function stringify( this )
return $"ClassB::stringify this={this} this.arg0={this.arg0} this.arg1={this.arg1}";
endfunction
endclass
class ClassC()
function ClassC( this, arg0, arg1 := "default.a1", arg2 := "default.a2" )
this.arg0 := arg0;
this.arg1 := arg1;
this.arg2 := arg2;
endfunction
function stringify( this )
return $"ClassC::stringify this={this} this.arg0={this.arg0} this.arg1={this.arg1} this.arg2={this.arg2}";
endfunction
endclass
class ClassD()
function ClassD( this, arg0, arg1 := "default.a1", arg2 := "default.a2", args ... )
this.arg0 := arg0;
this.arg1 := arg1;
this.arg2 := arg2;
this.args := args;
endfunction
function stringify( this )
return $"ClassD::ClassD this={this} this.arg0={this.arg0} this.arg1={this.arg1} this.arg2={this.arg2} this.args={this.args}";
endfunction
endclass
print( @ClassA.new() );
print( @ClassA.new( "a0" ).stringify() );
print( @ClassA.new( "a0", "a1" ) );
print( "-" );
print( @ClassB.new() );
print( @ClassB.new( "a0" ).stringify() );
print( @ClassB.new( "a0", "a1" ).stringify() );
print( @ClassB.new( "a0", "a1", "a2" ) );
print( "-" );
print( @ClassC.new() );
print( @ClassC.new( "a0" ).stringify() );
print( @ClassC.new( "a0", "a1" ).stringify() );
print( @ClassC.new( "a0", "a1", "a2" ).stringify() );
print( @ClassC.new( "a0", "a1", "a2", "a3" ) );
print( "-" );
print( @ClassD.new() );
print( @ClassD.new( "a0" ).stringify() );
print( @ClassD.new( "a0", "a1" ).stringify() );
print( @ClassD.new( "a0", "a1", "a2" ).stringify() );
print( @ClassD.new( "a0", "a1", "a2", "a3" ).stringify() );
print( @ClassD.new( "a0", "a1", "a2", "a3", "a4" ).stringify() );
print( @ClassD.new( "a0", "a1", "a2", "a3", "a4", "a5" ).stringify() );