zephir
zephir copied to clipboard
Improved Compilation Error Message: Say proper things when a method variable is declared while a parameter is already used
protected function doStuff(var theThings, bool correctly = false)
{
var correctly;
var_export(correctly);
}
public final function __construct(<DiInterface> di)
{
this->doStuff("abc", true);
}
dschissler@box1:/opt/project$ zephir build
Warning: Variable "correctly" declared but not used in Project\Application::doStuff in /opt/project/project/Application.zep on 24 [unused-variable]
var correctly;
---------------------^
Compiling...
Installing...
Internal extension compilation failed. Check compile-errors.log for more information
compile-errors.log
/opt/extension/ext/project/application.zep.c: In function ‘zim_Project_Application_doStuff’:
/opt/extension/ext/project/application.zep.c:57:13: error: incompatible types when assigning to type ‘zval {aka struct _zval_struct}’ from type ‘int’
correctly = 0;
^
/opt/extension/ext/project/application.zep.c:59:13: error: incompatible types when assigning to type ‘zval {aka struct _zval_struct}’ from type ‘int’
correctly = zephir_get_boolval(correctly_param);
^
make: *** [project/application.lo] Error 1
/opt/extension/ext/project/application.zep.c: In function ‘zim_Project_Application_doStuff’:
/opt/extension/ext/project/application.zep.c:57:13: error: incompatible types when assigning to type ‘zval {aka struct _zval_struct}’ from type ‘int’
correctly = 0;
^
/opt/extension/ext/project/application.zep.c:59:13: error: incompatible types when assigning to type ‘zval {aka struct _zval_struct}’ from type ‘int’
correctly = zephir_get_boolval(correctly_param);
^
make: *** [project/application.lo] Error 1
So that obviously isn't very helpful. I can work around it through since I learned that this gibberish can be mapped to a useful phrase or sentence made up of my private understanding of the situation.
This just struck me again during a refactor. Its difficult because not many languages require you to declare variable beforehand but then don't offer assistance around that.