polserver/testsuite/escript/classes/this-reassignment.src
Kevin Eady 0fa1b893a0 Update core-changes, break-changes for classes support (#719)
* Format testsuite escript

* Format testsuite pol

* Update docs
Switch "attributes" to "members" to better align with Escript terms.

* Add core-changes, breaking-changes
2024-10-10 18:06:04 +02:00

41 lines
843 B
Text

// Tests with modifying `this` in the constructor.
// We should never see `uninit` in the output.
class BaseClass()
function BaseClass( this )
print( $"BaseClass::BaseClass this={this}" );
endfunction
endclass
// Call super() before modifying this
class Foo1( BaseClass )
function Foo1( this )
print( $"Foo1::Foo1 this={this}" );
super();
this := uninit;
print( $"Foo1::Foo1 this={this}" );
endfunction
endclass
var f1 := Foo1();
print( f1 );
print( "----" );
// Call super() after modifying this
class Foo2( BaseClass )
function Foo2( this )
print( $"Foo2::Foo2 this={this}" );
this := uninit;
super();
print( this );
endfunction
endclass
var f2 := Foo2();
print( f2 );
print( "----" );
// As usual, we can re-assign the variable that _holds_ a class instance.
f2 := "abc";
print( f2 );