You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While implementing a new feature - #676 Strict type option - I'm curious what people think about is it must be by default on.
In short being a dynamic language, it is possible to send a message even if we know that the class does not handle it now.
For example the compiler will warn that the following code may lead to an exception:
A;
public program()
{
A a := new A();
a.test();
}
The result of the compilation will be:
ELENA Command-line compiler 6.5.103 (C)2005-2024 by Aleksey Rakov, ELENA-LANG Org
Project: sandbox, Platform: Win_x86, Target type: STA Console
Cleaning up
Parsing sandbox.l
Compiling sandbox
sandbox.l(7:6): warning 407: Message 'test' does not handled by the object
.
saving sandbox
Successfully compiled
Linking..
Successfully linked
And this is an expected behavior, we cannot guarantee that someone will not override the class A and add a support for this method. But it is worth to warn in case it is an miss spelling.
But there are situation when we know it exactly, if the class is sealed.
E.g. if we change the code like this:
sealed A;
public program()
{
A a := new A();
a.test();
}
In this case the class A cannot be inherited so the message will never handle directly.
So starting from 6.5 version a new option - Strict type enforcing is introduced. If the compile the code like this:
elena-cli.exe sandbox.l -xs
the compiler will generate an error:
ELENA Command-line compiler 6.5.103 (C)2005-2024 by Aleksey Rakov, ELENA-LANG Org
Project: sandbox, Platform: Win_x86, Target type: STA Console
Strict type enforcing is on
Cleaning up
Parsing sandbox.l
Compiling sandbox
sandbox.l(7:6): error 185: Message 'test' does not handled by the object
Compiled with errors
So my question is do this behavior must be default? What do you think?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
While implementing a new feature - #676 Strict type option - I'm curious what people think about is it must be by default on.
In short being a dynamic language, it is possible to send a message even if we know that the class does not handle it now.
For example the compiler will warn that the following code may lead to an exception:
The result of the compilation will be:
And this is an expected behavior, we cannot guarantee that someone will not override the class A and add a support for this method. But it is worth to warn in case it is an miss spelling.
But there are situation when we know it exactly, if the class is sealed.
E.g. if we change the code like this:
In this case the class A cannot be inherited so the message will never handle directly.
So starting from 6.5 version a new option - Strict type enforcing is introduced. If the compile the code like this:
the compiler will generate an error:
So my question is do this behavior must be default? What do you think?
1 vote ·
Beta Was this translation helpful? Give feedback.
All reactions