-
Notifications
You must be signed in to change notification settings - Fork 170
x: i32[3] = [1, 2, 3] fails #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The builtin module is not loaded for the "print_arr" pass. A workaround it to force the frontend to load it:
This is a long standing issue, the frontend should either always load the module, so that the ASR passes can use it, or perhaps the pass would accept a callback to load the module if it is not present (that might be the best way). Now it compiles, but prints:
Which is another bug. |
One can also do:
which also prints:
|
def main0():
x: i32[3] = [1, 2, 3]
x[0] = 5
print(x[0])
x[2] = -4
print(x[2])
x[1] = x[0] + x[2]
print(x[1])
main0() This works, though: $ lpython t.py && ./a.out
5
-4
1 |
Probably |
OK, so I figured that the semantic error: Type mismatch for an annotation-assignment. In LPython, the types must be compatible.
--> t.py:2:5
|
2 | x: i32[3] = [1, 2, 3]
| ^ ^^^^^^^^^ type mismatch (integer and list)
See #370 . |
Now it prints: semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> a.py:2:5
|
2 | x: i32[3] = [1, 2, 3]
| ^ ^^^^^^^^^ type mismatch ('i32' and 'list[i32]') |
The error message should say: |
But this code: from numpy import empty
def main0():
x: f64[3]
x = empty(3)
# x: i32[3] = array([1, 2, 3])
print(x)
main0() gives $ lpython a.py
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 879
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir, compiler_options, time_report);
File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 373
res = fe.get_llvm3(*asr, diagnostics);
File "/Users/ondrej/repos/lpython/src/lpython/python_evaluator.cpp", line 54
= asr_to_llvm(asr, diagnostics,
File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 4522
pass_replace_print_arr(al, asr, rl_path);
File "/Users/ondrej/repos/lpython/src/libasr/pass/print_arr.cpp", line 85
v.visit_TranslationUnit(unit);
File "../libasr/asr.h", line 3224
File "../libasr/asr.h", line 3089
File "../libasr/asr.h", line 2900
File "../libasr/pass/pass_utils.h", line 135
File "../libasr/pass/pass_utils.h", line 91
File "../libasr/asr.h", line 3103
File "../libasr/asr.h", line 2934
File "/Users/ondrej/repos/lpython/src/libasr/pass/print_arr.cpp", line 55
head.m_start = PassUtils::get_bound(arr_expr, i + 1, "lbound", al, unit, rl_path, current_scope);
File "/Users/ondrej/repos/lpython/src/libasr/pass/pass_utils.cpp", line 329
unit, rl_path, current_scope, arr_expr->base.loc);
File "/Users/ondrej/repos/lpython/src/libasr/pass/pass_utils.cpp", line 257
ASR::Module_t *m = LFortran::ASRUtils::load_module(al, current_scope,
File "/Users/ondrej/repos/lpython/src/libasr/asr_utils.cpp", line 105
loc);
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/functional", line 2560
return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/functional", line 1885
return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/functional", line 1732
return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/functional", line 1558
return _Invoker::__call(__f_.first(),
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/__functional_base", line 348
_VSTD::__invoke(_VSTD::forward<_Args>(__args)...);
File "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/type_traits", line 2577
{
File "/Users/ondrej/repos/lpython/src/libasr/pass/pass_utils.cpp", line 260
[&](const std::string &msg, const Location &) { throw LFortranException(msg); });
LFortranException: Module 'lfortran_intrinsic_builtin' not declared in the current source and the modfile was not found |
The following code works now: from ltypes import f64
from numpy import empty
def main0():
x: f64[3]
x = empty(3)
# x[0] = 2.
# x[1] = -3.
# x[2] = x[1] + x[0]
print(x)
main0() Output: $ lpython examples/expr2.py; ./a.out
0.00000000000000000
0.00000000000000000
0.00000000000000000 |
@certik, is this issue resolved? |
I think everything works here now. Thanks! |
This prints:
The text was updated successfully, but these errors were encountered: