@@ -631,69 +631,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
631631 .left_shift {
632632 if left_final_sym.kind == .array
633633 || c.table.sym (c.unwrap_generic (left_type)).kind == .array {
634- if ! node.is_stmt {
635- c.error ('array append cannot be used in an expression' , node.pos)
636- }
637- if left_type.has_flag (.option) && node.left is ast.Ident
638- && node.left.or_expr.kind == .absent {
639- c.error ('unwrapped Option cannot be used in an infix expression' ,
640- node.pos)
641- }
642- // `array << elm`
643- c.check_expr_option_or_result_call (node.right, right_type)
644- node.auto_locked , _ = c.fail_if_immutable (mut node.left)
645- left_value_type := c.table.value_type (c.unwrap_generic (left_type))
646- left_value_sym := c.table.sym (c.unwrap_generic (left_value_type))
647- if ! left_value_type.has_flag (.option) && right_type.has_flag (.option) {
648- c.error ('unwrapped Option cannot be used in an infix expression' ,
649- node.pos)
650- }
651- if left_value_sym.kind == .interface {
652- if right_final_sym.kind != .array {
653- // []Animal << Cat
654- if c.type_implements (right_type, left_value_type, right_pos) {
655- if ! right_type.is_any_kind_of_pointer () && ! c.inside_unsafe
656- && right_sym.kind != .interface {
657- c.mark_as_referenced (mut & node.right, true )
658- }
659- }
660- } else {
661- // []Animal << []Cat
662- c.type_implements (c.table.value_type (right_type), left_value_type,
663- right_pos)
664- }
665- return ast.void_type
666- } else if left_value_sym.kind == .sum_type {
667- if right_sym.kind != .array {
668- if ! c.table.is_sumtype_or_in_variant (left_value_type, ast.mktyp (c.unwrap_generic (right_type))) {
669- c.error ('cannot append `${right_sym.name} ` to `${left_sym.name} `' ,
670- right_pos)
671- }
672- } else {
673- right_value_type := c.table.value_type (c.unwrap_generic (right_type))
674- if ! c.table.is_sumtype_or_in_variant (left_value_type, ast.mktyp (right_value_type)) {
675- c.error ('cannot append `${right_sym.name} ` to `${left_sym.name} `' ,
676- right_pos)
677- }
678- }
679- return ast.void_type
680- }
681- // []T << T or []T << []T
682- unwrapped_right_type := c.unwrap_generic (right_type)
683- if c.check_types (unwrapped_right_type, left_value_type) {
684- // []&T << T is wrong: we check for that, !(T.is_ptr()) && ?(&T).is_ptr()
685- if ! (! unwrapped_right_type.is_ptr () && left_value_type.is_ptr ()
686- && left_value_type.share () == .mut_t) {
687- return ast.void_type
688- }
689- } else if c.check_types (unwrapped_right_type, c.unwrap_generic (left_type)) {
690- return ast.void_type
691- }
692- if left_value_type.has_flag (.option) && right_type == ast.none_type {
693- return ast.void_type
694- }
695- c.error ('cannot append `${right_sym.name} ` to `${left_sym.name} `' , right_pos)
696- return ast.void_type
634+ return c.check_append (mut node, left_type, right_type, right_final_sym)
697635 } else {
698636 node.promoted_type = c.check_shift (mut node, left_type, right_type)
699637 return node.promoted_type
0 commit comments