ELENA-LANG / elena-lang

ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
https://elena-lang.github.io/
MIT License
227 stars 23 forks source link

Nullable support #562

Open arakov opened 1 year ago

arakov commented 1 year ago

Is your feature request related to a problem? Please describe. Compiler should warn if the operation with nil is possible. Nil-safe code should be used instead. Only implicitly nullable types should allow operation where the target can be nil

Describe the solution you'd like The type declaration should have a special attribute ?

import extensions;

singleton Tester
{
   test(int? prm)
   {
      ^ prm.hasValue ? (prm.Value) : 0
   }
}

public program()
{
   var t := Tester;

   console.printLine("Tester.test(2)=",Tester.test(2));
   console.printLine("t.test(3)=",t.test(3));

   console.printLine("Tester.test(nil)=",Tester.test(nil));
   console.printLine("t.test(nil)=",t.test(nil));
}   

The nullable structures are special case - they are in fact a reference type

Open issues:

arakov commented 5 months ago