Skip to content

Method Call

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Method Call

Methods are called by giving the subject value followed by a dot and the name of the method and then the supplied arguments surrounded by parentheses, separated by commas.

subject_value.someMethod(argument1, argument2, argument3, argumentN)

Method Resolution

Which method should be called is determined in two stages.

In the first stage, a strict search is done, which will match any methods with the same name, base type, number of arguments, and argument types. If no matches are found in the first search stage, then the second stage will begin and a looser search is done.

The second looser search will match any methods with the same name, base type, compatible number of arguments, and allowed argument deviations. Allowed argument deviations include: ptr to pointer types, pointer to bool decay, compatible floating-point values, compatible integer values, and user-defined implicit conversions.

Polymorphic methods can match during either stage, after non-polymorphic methods are checked.

If no other factor can be used to select which should be used, then the first possible method declared will be selected.

Subject Mutability

If the supplied subject value isn't mutable, then it will be pushed onto the stack in order to make the method call.

Argument Passing

Values that have a corresponding __pass__ function, will be passed through __pass__ before the method receives them. The subject value is always immune to this, because it will always be a pointer.

Result Value

The resulting value is the value returned by the method. If the method returns void, then it cannot be used within an expression, but only as a statement.

Neglected Return Values

If the callee returns a value that is ignored and the ignored value has a __defer__, then the corresponding __defer__ will implicitly be called on the neglected value.

Tentative Method Calls

Method calls can be made tentative by adding a ? after the . in the method call.

subject_value.?doSomething()

Tentative method calls will collapse to void if the compiler cannot compile them.

Specifying Return Type

The ~> operator can be used to target a specific version of a method that returns a certain type.

subject_value.getValue() ~> int
Clone this wiki locally