Skip to content

cmd/compile: compiler does not allow "direct binding" of function return values to copy arguments #15992

@momchil-velikov

Description

@momchil-velikov

go version devel +2f08888 Tue Jun 7 06:04:23 2016 +0000 linux/amd64

The spec allows "forwarding"/"direct binding" of return values to function arguments
https://golang.org/ref/spec#Calls

As a special case, if the return values of a function or method g are equal in number and individually
assignable to the parameters of another function or method f, then the call f(g(parameters_of_g)) will
invoke f after binding the return values of g to the parameters of f in order.

For the following program (https://play.golang.org/p/YEJSEfQLA8):

package main

import (
    "fmt"
)

func f(a []byte) ([]byte, []byte) {
    return a, []byte("abc")
}

func g(a []byte) ([]byte, string) {
    return a, "abc"
}

func main() {
    a := []byte{1, 2, 3}
    n := copy(f(a))
    fmt.Println(n, a)

    b := []byte{1, 2, 3}
    n = copy(f(b))
    fmt.Println(n, b)
}

the compiler issues messages

prog.go:17: missing arguments to copy
prog.go:21: missing arguments to copy

The same program passes when compiled via gotypes and gccgo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions