polserver/testsuite/escript/classes/method-member.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

39 lines
1.1 KiB
Text

// Add a funcref member and call it.
class Foo()
function Foo( this, name, use_member )
this.name := name;
if ( use_member )
this.bar := @( prefix ) { print( $"Member {prefix}: {this.name}" ); };
endif
this.baz := @StaticFunc;
this.number := 1234;
endfunction
// Should not be called, since `this.bar` is assigned in ctor.
function bar( this, prefix )
print( $"Class {prefix} {this.name}" );
endfunction
endclass
function StaticFunc( arg0 )
print( $"::StaticFunc arg0={arg0}" );
endfunction
var foo := Foo( "NAME", true );
foo.bar( "PREFIX" );
foo.baz( "ARG0" );
print( $"foo.name equals 'NAME'? {foo.name == "NAME"}" );
// Method not found error: errortext = "Method 'blubb' not found in class 'Foo'"
print( foo.blubb() );
// Member not callable, but we still try to "call" it: errortext = "Method 'number' not found"
// Notice the different error message from a not found method.
print( foo.number() );
print( "----" );
// Create a new Foo that does _not_ assign a member
foo := Foo( "NAME2", false );
foo.bar( "PREFIX2" );