@@ -551,16 +551,9 @@ fn builtinCallerAppend(mut e: &eval, mut fc: &ast::CallExpr, mut v: &Value): &Va
551551 ret nil
552552 }
553553
554- if e.s.meta.runtime != nil {
555- // Add instance to relevant runtime function for slice type if not exist.
556- mut f := runtimeFindFunc(e.s.meta.runtime, "memappend").instanceForce()
557- f.Generics = append(f.Generics, &InsGeneric{Type: t.Type}, &InsGeneric{Type: e1.Type})
558- ok, _ := e.s.checkGenericFunc(&f, fc.Token)
559- if !ok {
560- panic("sema: memappend evaluation failed, this is an implementation mistake")
561- }
562- e.pushReference(f)
563- }
554+ // Save the type of e1.
555+ mut e1typ := e1.Type
556+
564557 // Source should use the same type with destination.
565558 // So, to make e1 unvariadic, use type of the destination.
566559 mut elems := new(Value, *e1)
@@ -575,16 +568,31 @@ fn builtinCallerAppend(mut e: &eval, mut fc: &ast::CallExpr, mut v: &Value): &Va
575568 // Before the analysis, set variadic kind as not variadic.
576569 // This is should be made to avoid mutability error for base type of slice.
577570 // Element types should still be checked.
578- // Since the variadiced slice will not mutated, just check mutability risk of elements.
571+ // Since the variadiced slice will not be mutated,
572+ // just check mutability risk of elements.
579573 e1.Type.Variadic = false
580574
581575 if e.s.checkValidityForInitExpr(mutable, reference, s.Value, e1, secondArg.Token) {
582576 e1.Type.Variadic = true
583577 // Check type if validity is good.
584578 // Helps to reduce error logs and duplicated logs.
585- _ = e.s.checkAssignType(reference, firstAssignToDest, s.Value, e1, secondArg.Token, e.getOwnerRefers())
579+ if !e.s.checkAssignType(reference, firstAssignToDest, s.Value, e1, secondArg.Token, e.getOwnerRefers()) {
580+ ret nil
581+ }
586582 } else {
587583 e1.Type.Variadic = true
584+ ret nil
585+ }
586+
587+ if e.s.meta.runtime != nil {
588+ // Add instance to relevant runtime function for slice type if not exist.
589+ mut f := runtimeFindFunc(e.s.meta.runtime, "memappend").instanceForce()
590+ f.Generics = append(f.Generics, &InsGeneric{Type: t.Type}, &InsGeneric{Type: e1typ})
591+ ok, _ := e.s.checkGenericFunc(&f, fc.Token)
592+ if !ok {
593+ panic("sema: memappend evaluation failed, this is an implementation mistake")
594+ }
595+ e.pushReference(f)
588596 }
589597
590598 ret v
@@ -606,7 +614,11 @@ fn builtinCallerAppend(mut e: &eval, mut fc: &ast::CallExpr, mut v: &Value): &Va
606614 if e.s.checkValidityForInitExpr(mutable, reference, s.Value, e1, arg.Token) {
607615 // Check type if validity is good.
608616 // Helps to reduce error logs and duplicated logs.
609- _ = e.s.checkAssignType(reference, firstAssignToDest, s.Value, e1, arg.Token, e.getOwnerRefers())
617+ if !e.s.checkAssignType(reference, firstAssignToDest, s.Value, e1, arg.Token, e.getOwnerRefers()) {
618+ ret nil
619+ }
620+ } else {
621+ ret nil
610622 }
611623 slice.Elems = append(slice.Elems, e1)
612624 }
0 commit comments