Skip to content

Commit

Permalink
per PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Dec 21, 2022
1 parent d2a796f commit 0f1fe4f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pyteal/ast/abi/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pyteal.ast.expr import Expr
from pyteal.ast.abstractvar import AbstractVar, alloc_abstract_var
from pyteal.ast.seq import Seq
from pyteal.errors import TealInputError
from pyteal.errors import TealInputError, TealTypeError
from pyteal.types import TealType


Expand Down Expand Up @@ -215,6 +215,8 @@ def produced_type_spec(self) -> TypeSpec:
return self.type_spec

def store_into(self, output: BaseType) -> Expr:
from pyteal.ast.subroutine import SubroutineDeclaration

if output.type_spec() != self.produced_type_spec():
raise TealInputError(
f"expected type_spec {self.produced_type_spec()} but get {output.type_spec()}"
Expand All @@ -223,20 +225,23 @@ def store_into(self, output: BaseType) -> Expr:
# HANG NOTE! This get_declaration check applies only for pre frame pointer case
# the post frame pointer case should not apply
# need to somehow expose the context of evaluation

declaration: SubroutineDeclaration | None = None
try:
declaration = self.computation.subroutine.get_declaration_by_option(False)
except Exception:
pass

if declaration is not None:
if declaration.deferred_expr is None:
raise TealInputError(
"ABI return subroutine must have deferred_expr to be not-None."
)
if declaration.deferred_expr.type_of() != output.type_spec().storage_type():
raise TealInputError(
f"ABI return subroutine deferred_expr is expected to be typed {output.type_spec().storage_type()}, "
f"but has type {declaration.deferred_expr.type_of()}."
raise TealTypeError(
declaration.deferred_expr.type_of(),
output.type_spec().storage_type(),
)
except Exception:
pass

return output._stored_value.store(self.computation)

Expand Down

0 comments on commit 0f1fe4f

Please sign in to comment.