sun::types::ErrorUnionType

sun::types::ErrorUnionType

class · Source (opens in a new tab)

class sun::types::ErrorUnionType : public sun::types::Type

Error union type - represents a type that can be either a value or an error Following Zig's model where errors are values Represented as a struct { bool isError; union { ValueType value; i32 errorCode; } } For simplicity, we use { i1 isError, T value } where we check isError first.

Inherits

Public Functions

ErrorUnionType

public · function · Source (opens in a new tab)

sun::types::ErrorUnionType::ErrorUnionType(TypePtr value)

Creates a result type that can hold either a value or an error.

Related: TypePtr

equals

public · function · Source (opens in a new tab)

bool sun::types::ErrorUnionType::equals(const Type &other) const override

Reports whether the other type has the same semantic identity.

Related: Type

getKind

public · function · Source (opens in a new tab)

Kind sun::types::ErrorUnionType::getKind() const override

Returns the type category used for semantic checks and dispatch.

Related: Kind

getValueLLVMType

public · function · Source (opens in a new tab)

llvm::Type * sun::types::ErrorUnionType::getValueLLVMType(llvm::LLVMContext &ctx) const

Get the LLVM type of the value (for extracting the value when not an error).

getValueType

public · function · Source (opens in a new tab)

const TypePtr & sun::types::ErrorUnionType::getValueType() const

Returns the value type stored by this object.

Related: TypePtr

toDisplayString

public · function · Source (opens in a new tab)

std::string sun::types::ErrorUnionType::toDisplayString() const override

Spelled the way the source spells it: "i32 throws IError".

toLLVMType

public · function · Source (opens in a new tab)

llvm::Type * sun::types::ErrorUnionType::toLLVMType(llvm::LLVMContext &ctx) const override

Error union is represented as a struct: { i1 isError, <valueType> value } If isError is true, the error code is stored in the value field (as i64).

toString

public · function · Source (opens in a new tab)

std::string sun::types::ErrorUnionType::toString() const override

Returns a readable representation for diagnostics and debugging.

Public Fields

StaticKind

public · variable · static · Source (opens in a new tab)

Kind sun::types::ErrorUnionType::StaticKind = Kind::ErrorUnion

No documentation comment.

Related: Kind, Kind::ErrorUnion

Private Fields

valueType

private · variable · Source (opens in a new tab)

TypePtr sun::types::ErrorUnionType::valueType

No documentation comment.

Related: TypePtr