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
{{ message }}
Repository navigation
Declaring a u16 function breaks the % operation #2146
$ lpython a.py warning: The module 'lpython_builtin' located in /Users/ondrej/repos/lpython/src/bin/../runtime/lpython_builtin.py cannot be loaded --> a.py:5:15 |5 | print(i16(i % 1023)) | ^^^^^^^^ imported heresemantic error: Unsupported type annotation: u16 --> /Users/ondrej/repos/lpython/src/bin/../runtime/lpython_builtin.py:504:26 |504 | def _lpython_floordiv(a: u16, b: u16) -> u16: | ^^^
The issue is likely here:
ASR::ttype_t* get_type_from_var_annotation(std::string var_annotation,
const Location& loc, Vec<ASR::dimension_t>& dims,
AST::expr_t** m_args=nullptr, size_t n_args=0,
bool raise_error=true, ASR::abiType abi=ASR::abiType::Source,
bool is_argument=false) {
ASR::ttype_t* type = nullptr;
ASR::symbol_t *s = current_scope->resolve_symbol(var_annotation);
if (s) {
if (ASR::is_a<ASR::Variable_t>(*s)) {
...
Where it finds s as a "user" function. However this function was declared below and in the main module, not the built-in module, so unless the module is inlined, this shouldn't happen.
Finally, the error message should point to the user defined function and say that it can't be used for annotation.
Since #2049 we were using the same Translation_Unit_t/global_scope across modules. The symbols defined in the main_module get added to the Translation_Unit_t/global_scope. Due to this, other modules are able to access the symbols defined in the main_module (as the global_scope is shared with them). I think, therefore, the error described in this issue occurs.
I fixed this issue in #2161 by processing/forming the main_module as a Module_t (and embedding it inside the Translation_Unit_t. This way the symbols defined in the main_module are not added to the global scope (but instead to the module scope) and thus are not accessible by other modules.
Activity
TEST: Add test for scoping issue
ubaidsk commentedon Jul 15, 2023
Since #2049 we were using the same
Translation_Unit_t/global_scopeacross modules. The symbols defined in themain_moduleget added to theTranslation_Unit_t/global_scope. Due to this, other modules are able to access the symbols defined in themain_module(as theglobal_scopeis shared with them). I think, therefore, the error described in this issue occurs.I fixed this issue in #2161 by processing/forming the
main_moduleas aModule_t(and embedding it inside theTranslation_Unit_t. This way the symbols defined in themain_moduleare not added to the global scope (but instead to the module scope) and thus are not accessible by other modules.TEST: Add test for scoping issue
certik commentedon Jul 16, 2023
@Shaikh-Ubaid awesome, great job!
I think this is a cleaner solution.