Socordia
  • Intro
    • The Compiler
  • The Basics
    • Variables
      • Arrays
    • Conditional Flow
    • Loops
    • Functions
    • Data
      • Casting
      • Enumerations
      • Ranges/Aliases
      • Structs
      • Tuples
      • Unit of Measure Types
  • Mixins
  • Accessibility
  • Primitive Datatypes
  • Extended
    • Conditional
    • Inline IL
    • Operator Overloading
    • Unions
    • OOP
      • Classes
      • Interfaces
Powered by GitBook
On this page
  • Implicit Casts
  • Explicit Casts
  1. The Basics
  2. Data

Casting

Implicit Casts

Sometimes you want to pass number values of a specific type that is smaller than the required type. Socordia allows you to use those values by an implicit cast. For example: you can use a i32 value if a variable has the type i64. This can be done so long as the two types are of the same kind, e.g. integer and integer; or float and float.

You can also write a custom operator overload to make your custom types implicitly castable.

Explicit Casts

You can always try to cast a value to another type with the as operator. If this is not successful it will return none.

PreviousDataNextEnumerations

Last updated 4 months ago