Skip to content

enhancement: narrow fallibility of cast — compile-time string literals are infallible #107

Description

@sentomk

Summary

Currently int(s) treats all string sources as fallible, requiring ?: even when s is a compile-time literal that cannot fail. The checker should distinguish compile-time-known strings from runtime inputs.

Changes

  1. Narrow fallibility detection in the checker:
    • String literal / compile-time-known string → cast is infallible, no ?: required
    • Runtime input (io::in(), function params, variables) → keep fallible, ?: required
  2. Remove ? postfix propagation syntax (int? x = int(s)?)

Examples

string s = "42";
int x = int(s);         // OK — compile-time literal

string age = io::in();
int y = int(age);       // ERROR — runtime input, must use ?:
int z = int(age) ?: 0;  // OK

Testing

  • sema pass: literal string to numeric cast without ?:
  • sema fail: runtime string to numeric cast without ?:
  • sema fail: ? postfix propagation rejected

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions