From b99019fe28ff82f90cee3f40e28a8d2b1ba4be92 Mon Sep 17 00:00:00 2001 From: faze-geek Date: Thu, 23 Jun 2022 08:44:23 +0530 Subject: [PATCH] correct_error --- src/lpython/semantics/python_ast_to_asr.cpp | 4 ---- tests/errors/test_str_mismatch.py | 8 ++++++++ tests/reference/asr-test_str_mismatch-4aad88f.json | 13 +++++++++++++ .../reference/asr-test_str_mismatch-4aad88f.stderr | 5 +++++ tests/tests.toml | 4 ++++ 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tests/errors/test_str_mismatch.py create mode 100644 tests/reference/asr-test_str_mismatch-4aad88f.json create mode 100644 tests/reference/asr-test_str_mismatch-4aad88f.stderr diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 24954b8429..990a8ecc3d 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -950,10 +950,6 @@ class CommonVisitor : public AST::BaseVisitor { al, right->base.loc, right, ASR::cast_kindType::LogicalToInteger, int_type)); return ASR::down_cast(ASRUtils::make_Cast_t_value( al, right->base.loc, right, ASR::cast_kindType::IntegerToComplex, left_type)); - } else { - std::string rtype = ASRUtils::type_to_str_python(right_type); - throw SemanticError("Casting " + rtype + " to complex is not Implemented", - right->base.loc); } } if (!is_assign) { // This will only be used for BinOp diff --git a/tests/errors/test_str_mismatch.py b/tests/errors/test_str_mismatch.py new file mode 100644 index 0000000000..fbecc1942c --- /dev/null +++ b/tests/errors/test_str_mismatch.py @@ -0,0 +1,8 @@ +def main(): + s : str + c : c32 + c = 1+ 1j + s = "abc" + c + print(s) + +main() \ No newline at end of file diff --git a/tests/reference/asr-test_str_mismatch-4aad88f.json b/tests/reference/asr-test_str_mismatch-4aad88f.json new file mode 100644 index 0000000000..24e48dca5c --- /dev/null +++ b/tests/reference/asr-test_str_mismatch-4aad88f.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_str_mismatch-4aad88f", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_str_mismatch.py", + "infile_hash": "cb0d79659e231dea35ff7fb9a0b3d61ea4e61a97a084dd4ef5897a74", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_str_mismatch-4aad88f.stderr", + "stderr_hash": "e64e38a8c35e63d2f542f67e1d133be318f46eac1f0e5aa1f187ca19", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_str_mismatch-4aad88f.stderr b/tests/reference/asr-test_str_mismatch-4aad88f.stderr new file mode 100644 index 0000000000..4512ec7f9f --- /dev/null +++ b/tests/reference/asr-test_str_mismatch-4aad88f.stderr @@ -0,0 +1,5 @@ +semantic error: Type mismatch in binary operator; the types must be compatible + --> tests/errors/test_str_mismatch.py:5:9 + | +5 | s = "abc" + c + | ^^^^^ ^ type mismatch (str and c32) diff --git a/tests/tests.toml b/tests/tests.toml index 52be4f8d21..fcb995d406 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -575,3 +575,7 @@ tokens = true [[test]] filename = "errors/test_tuple1.py" asr = true + +[[test]] +filename = "errors/test_str_mismatch.py" +asr = true \ No newline at end of file