Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 1, 2023
1 parent e17bccd commit 09e5609
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/parser/types/numbers/test_decimals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from vyper.exceptions import DecimalOverrideException, InvalidOperation
from vyper.exceptions import DecimalOverrideException, InvalidOperation, TypeMismatch
from vyper.utils import DECIMAL_EPSILON, SizeLimits


Expand Down Expand Up @@ -261,4 +261,4 @@ def foo() -> decimal:
return 2.2 ** 2.0
"""

assert_compile_failed(lambda: get_contract(code), InvalidOperation)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)
4 changes: 2 additions & 2 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,9 +1088,9 @@ def fetch_call_return(self, node):
if revert_on_failure is not None:
revert_on_failure = get_folded_value(revert_on_failure)

revert_on_failure = revert_on_failure if revert_on_failure is not None else True
revert_on_failure = revert_on_failure.value if revert_on_failure is not None else True

if outsize is None or outsize == 0:
if outsize is None or outsize.value == 0:
if revert_on_failure:
return None
return BoolT()
Expand Down
11 changes: 8 additions & 3 deletions vyper/semantics/analysis/pre_typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def visit_FunctionDef(self, node):
# visit type annotations of arguments
# e.g. def foo(a: DynArray[uint256, 2 ** 8]): ...
for arg in node.args.args:
self.visit(arg.annotation)
if arg.annotation:
self.visit(arg.annotation)

for kwarg in node.args.defaults:
self.visit(kwarg)
Expand All @@ -94,7 +95,7 @@ def visit_StructDef(self, node):

def visit_VariableDecl(self, node):
self.visit(node.annotation)
if node.is_constant:
if node.is_constant and node.value:
self.visit(node.value)

# Stmts
Expand Down Expand Up @@ -156,7 +157,7 @@ def visit_Attribute(self, node):
self.visit(node.value)
value_node = get_folded_value(node.value)
if isinstance(value_node, vy_ast.Dict):
for k, v in zip(node.keys, node.values):
for k, v in zip(value_node.keys, value_node.values):
if k.id == node.attr:
node._metadata["folded_value"] = v
return
Expand All @@ -168,6 +169,10 @@ def visit_BinOp(self, node):
left = get_folded_value(node.left)
right = get_folded_value(node.right)
if isinstance(left, type(right)) and isinstance(left, (vy_ast.Int, vy_ast.Decimal)):
if isinstance(node.op, (vy_ast.LShift, vy_ast.RShift)) and not (
0 <= right.value <= 256
):
return
value = node.op._op(left.value, right.value)
node._metadata["folded_value"] = type(left).from_node(node, value=value)

Expand Down

0 comments on commit 09e5609

Please sign in to comment.