Skip to content
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

Raise and Assert with non-memory msg lead to panicking #3787

Closed
trocher opened this issue Feb 19, 2024 · 0 comments · Fixed by #3877
Closed

Raise and Assert with non-memory msg lead to panicking #3787

trocher opened this issue Feb 19, 2024 · 0 comments · Fixed by #3877

Comments

@trocher
Copy link
Contributor

trocher commented Feb 19, 2024

Version Information

  • vyper Version (output of vyper --version): 4b4e188
  • OS: OSX
  • Python Version (output of python --version): 3.11.4

What's your issue about?

Raise and Assert make the compiler crash if the reason string is not a memory variable.

For example, compiling:

a:String[1]
@external
def foo():
    self.a = "a"
    raise self.a

leads to vyper.exceptions.CodegenPanic: unhandled exception 'int' object has no attribute 'typ', parse_Raise

The issue comes from the fact that make_byte_array_copier is given a memory pointer and not an IR node in Stmt._assert_reason()

vyper/vyper/codegen/stmt.py

Lines 180 to 183 in 4b4e188

if msg_ir.location != MEMORY:
buf = self.context.new_internal_variable(msg_ir.typ)
instantiate_msg = make_byte_array_copier(buf, msg_ir)
else:

How can it be fixed?

+++ b/vyper/codegen/stmt.py
@@ -179,7 +179,8 @@ class Stmt:
         # TODO maybe use ensure_in_memory
         if msg_ir.location != MEMORY:
             buf = self.context.new_internal_variable(msg_ir.typ)
-            instantiate_msg = make_byte_array_copier(buf, msg_ir)
+            dst = IRnode.from_list(buf, typ=msg_ir.typ, location=MEMORY)
+            instantiate_msg = make_byte_array_copier(dst, msg_ir)
         else:
             buf = _get_last(msg_ir)
             if not isinstance(buf, int):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant