Exemplo n.º 1
0
    def get_rhs(self, rhs: Expression, expected_type: AnnotatedTypeName):
        if isinstance(rhs, TupleExpr):
            if not isinstance(rhs, TupleExpr) or not isinstance(
                    expected_type.type_name, TupleType) or len(
                        rhs.elements) != len(expected_type.type_name.types):
                raise TypeMismatchException(expected_type, rhs.annotated_type,
                                            rhs)
            exprs = [
                self.get_rhs(a, e)
                for e, a, in zip(expected_type.type_name.types, rhs.elements)
            ]
            return replace_expr(rhs, TupleExpr(exprs)).as_type(
                TupleType([e.annotated_type for e in exprs]))

        instance = rhs.instanceof(expected_type)
        if not instance:
            raise TypeMismatchException(expected_type, rhs.annotated_type, rhs)
        else:
            if rhs.annotated_type.type_name != expected_type.type_name:
                rhs = self.implicitly_converted_to(rhs,
                                                   expected_type.type_name)

            if instance == 'make-private':
                return self.make_private(rhs, expected_type.privacy_annotation)
            else:
                return rhs
Exemplo n.º 2
0
 def make_private_if_not_already(self, ast: Expression):
     if ast.annotated_type.is_private():
         expected = AnnotatedTypeName(ast.annotated_type.type_name,
                                      Expression.me_expr())
         if not ast.instanceof(expected):
             raise TypeMismatchException(expected, ast.annotated_type, ast)
         return ast
     else:
         return self.make_private(ast, Expression.me_expr())
Exemplo n.º 3
0
 def handle_cast(self, expr: Expression, t: TypeName) -> AnnotatedTypeName:
     # because of the fake solidity check we already know that the cast is possible -> don't have to check if cast possible
     if expr.annotated_type.is_private():
         expected = AnnotatedTypeName(expr.annotated_type.type_name,
                                      Expression.me_expr())
         if not expr.instanceof(expected):
             raise TypeMismatchException(expected, expr.annotated_type,
                                         expr)
         return AnnotatedTypeName(t.clone(), Expression.me_expr())
     else:
         return AnnotatedTypeName(t.clone())