Struct TypeCoercion

Source
pub struct TypeCoercion<'a> {
    context: &'a CompilationContext,
}
Expand description

Handles all type coercion rules and operations

This module is responsible for determining when and how types can be automatically converted or coerced, particularly for unspecified literal types.

Fields§

§context: &'a CompilationContext

Implementations§

Source§

impl<'a> TypeCoercion<'a>

Source

pub fn new(context: &'a CompilationContext) -> Self

Creates a new type coercion handler

§Arguments
  • context - The compilation context for type information
Source

pub fn can_coerce(&self, source_type: &TypeId, target_type: &TypeId) -> bool

Checks if an unspecified literal can be coerced to a target type

§Arguments
  • source_type - The unspecified literal type
  • target_type - The target type to coerce to
§Returns

true if coercion is possible, false otherwise

Source

pub fn check_mixed_arithmetic_operation( &self, left_type: &TypeId, right_type: &TypeId, bin_expr: &BinaryExpr, ) -> SemanticResult

Checks for mixed-type arithmetic operations with coercion

Handles cases where unspecified literals can be coerced to match the other operand’s type in arithmetic operations.

§Arguments
  • left_type - Type of the left operand
  • right_type - Type of the right operand
  • bin_expr - The binary expression for context
§Returns

Result with the resulting type or an error

Auto Trait Implementations§

§

impl<'a> Freeze for TypeCoercion<'a>

§

impl<'a> RefUnwindSafe for TypeCoercion<'a>

§

impl<'a> Send for TypeCoercion<'a>

§

impl<'a> Sync for TypeCoercion<'a>

§

impl<'a> Unpin for TypeCoercion<'a>

§

impl<'a> UnwindSafe for TypeCoercion<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.