Skip to content

[Feature] Context-aware safe integer casts #96

@pabloosabaterr

Description

@pabloosabaterr

Description

Integer casts currently warn about possible precision loss even when the value is provably safe from surrounding conditions.

Warnings should be suppressed when the value range is known to be safe.

Example

a: i8 := ... 

if a >= 0 {
    // a ∈ [0, I8_MAX]

    b: u8 := a as u8   // should NOT warn 
}

c: u8 := a as u8       // should warn

Rule

A cast is safe if:

range(source) ⊆ range(target)

Benefit

  • Removes false precision-loss warnings
  • Improves static analysis

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededneeds-design"Requires architectural planning"

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions