From ade10319eef9c191c519da0cc23776952b121c73 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:39:37 +0800 Subject: [PATCH] fix as wei val --- vyper/builtins/functions.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index c870478f2e..5d2477a43a 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -1032,24 +1032,29 @@ def build_IR(self, expr, args, kwargs, context): denom_divisor = self.get_denomination(expr) with value.cache_when_complex("value") as (b1, value): - if value.typ in (UINT256_T, UINT8_T): - sub = [ - "with", - "ans", - ["mul", value, denom_divisor], - [ - "seq", + if isinstance(value.typ, IntegerT): + if not value.typ.is_signed: + sub = [ + "with", + "ans", + ["mul", value, denom_divisor], [ - "assert", - ["or", ["eq", ["div", "ans", value], denom_divisor], ["iszero", value]], + "seq", + [ + "assert", + [ + "or", + ["eq", ["div", "ans", value], denom_divisor], + ["iszero", value], + ], + ], + "ans", ], - "ans", - ], - ] - elif value.typ == INT128_T: - # signed types do not require bounds checks because the - # largest possible converted value will not overflow 2**256 - sub = ["seq", ["assert", ["sgt", value, -1]], ["mul", value, denom_divisor]] + ] + else: + # signed types do not require bounds checks because the + # largest possible converted value will not overflow 2**256 + sub = ["seq", ["assert", ["sgt", value, -1]], ["mul", value, denom_divisor]] elif value.typ == DecimalT(): sub = [ "seq",