Skip to content

Commit

Permalink
demo moving typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 3, 2023
1 parent 188d295 commit 3482846
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,11 @@ def evaluate(self, left, right) -> ExprNode:
raise UnfoldableNode("Node contains invalid field(s) for evaluation")

# this validation is performed to prevent the compiler from hanging
# on very large shifts and improve the error message for negative
# values.
# on very large shifts. the actual error is handled downstream.
if isinstance(self.op, (LShift, RShift)) and not (0 <= right.value <= 256):
raise InvalidLiteral("Shift bits must be between 0 and 256", right)
raise UnfoldableNode

value = self.op._op(left.value, right.value)
_validate_numeric_bounds(self, value)
return type(left).from_node(self, value=value)


Expand Down
4 changes: 4 additions & 0 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,11 @@ def visit_BinOp(self, node: vy_ast.BinOp, typ: VyperType) -> None:
self.visit(node.left, typ)

rtyp = typ
right = get_folded_value(node.right)
if isinstance(node.op, (vy_ast.LShift, vy_ast.RShift)):
if isinstance(right, vy_ast.Int) and not (0 <= right.value <= 256):
raise InvalidLiteral("Shift bits must be between 0 and 256", right)

rtyp = get_possible_types_from_node(node.right).pop()

validate_expected_type(node.right, rtyp)
Expand Down

0 comments on commit 3482846

Please sign in to comment.