Kipper-Lang / Kipper

The Kipper programming language for Browsers and Node.js 🦊✨ Made at HTL Leonding & JKU Linz
https://kipper-lang.org
GNU General Public License v3.0
26 stars 4 forks source link

[Feature] Implement `cast as`, `try as` and `force as` #685

Open Luna-Klatzer opened 1 month ago

Luna-Klatzer commented 1 month ago

Is there an existing proposal for this?

This feature does not exist in the latest version

Proposal

For easier and more intuitive type-checking, the user should be able to use one of the following casts to ensure the type of a variable:

Example:

var x: num = "2" cast as num; // fails at compile-time
...
var y: num = fetch(...) force as num; // known at runtime
...
var z: num | null = fun(...) try as num; // known at runtime

Exact behaviour / changes you want