Skip to content

Conversation

@MelbourneDeveloper
Copy link
Owner

TLDR

Float type support and arithmetic operations now return Result types for compile-time overflow safety. All arithmetic expressions (+, -, *, /, %) return Result<T, String> requiring explicit pattern matching.

What Was Added?

  • Float type: FLOAT token in grammar, FloatLiteral AST node, float type in Hindley-Milner type system
  • Result-wrapped arithmetic: All arithmetic operators return Result<int, String> or Result<float, String>
  • Type inference helpers: isNumericType(), isFloatType(), isIntOrResultInt(), unwrapResultType() for Result type handling
  • Numeric unification: unifyConcreteWithGeneric() to unify Result with Result[float] notation
  • Overflow detection: LLVM intrinsics (sadd_with_overflow, etc.) for runtime overflow checking

What Was Changed / Deleted?

  • Arithmetic operations: Changed from direct int/float returns to Result<T, String> for overflow safety (core_functions.go)
  • Type inference: Enhanced to handle Result types in arithmetic and auto-unwrap where safe (type_inference.go: +320 lines)
  • All test files: 50+ test files updated to pattern match arithmetic results
  • Fiber generation: Updated fiber message passing to handle Result types (fiber_generation.go)
  • Function signatures: Extended to support float parameters and Result returns (function_signatures.go)

How Do The Automated Tests Prove It Works?

  • make test passes all integration tests with Result-wrapped arithmetic
  • examples/tested/basics/* demonstrate correct pattern matching on arithmetic results
  • Fiber tests verify Result types work with concurrent operations
  • Type inference tests verify float/int unification and Result type handling
  • Error case tests (failscompilation/) verify overflow detection and proper error messages

Summarise Changes To The Spec Here

  • 0002-LexicalStructure.md: Added FLOAT literal syntax (3.14, 0.5, 100.0)
  • 0004-TypeSystem.md: Added float primitive, documented Result<T, E> wrapping for arithmetic
  • 0007-PatternMatching.md: Added requirement to match arithmetic results due to Result returns
  • 0013-ErrorHandling.md: Documented arithmetic overflow detection via Result types

@MelbourneDeveloper MelbourneDeveloper merged commit 8877795 into main Oct 27, 2025
1 check passed
@MelbourneDeveloper MelbourneDeveloper deleted the float branch October 27, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants