language · keyword ·

static

Attach a member to the type

complete-programcpudatakeywordyeho

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

static

Status: stable

Static plain data method

Use a constructor to establish valid starting data, an instance method for behavior that belongs to one value, and static only when no instance state is needed.

cpu · complete-program · type checked

thing pair
{
    int left
    int right
}

class pairMath
{
    static Make(int left, int right) returns pair
    {
        pair value = pair()
        value.left = left
        value.right = right
        return value
    }

    static Sum(pair value) returns int
    {
        return value.left + value.right
    }
}

pair value = pairMath.Make(20, 22)

if pairMath.Sum(value) == 42
{
    Console.Log("static-plain-data-method-ok")
}


project.mech
package = "tests.compiler.kyber.staticPlainDataMethod"
version = "0.1.0"
backend = "kyber"
osTarget = "windows"
archTarget = "x64"
selfContainedApp = false



Notes and source

Stored constructor values follow declaration order for the current value-data ABI.

Class dispatch remains a separate oracle-only boundary even though plain-data constructors and direct admitted calls run through Kyber.

yeho/tests/compiler/kyber/plain-data-constructor/start.yh; tests/compiler/kyber/legalized-call-forms/start.yh