Skip to content

Variadic parameters don't work if some of the args are expended and some aren't #2873

Closed
@gopherbot

Description

@gopherbot

by ficoos:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull", "hg update default", rebuild, and
retry
what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
// Compiles
func RfoldInt(op func(a, b int) int, ints ...int) int {
    if len(ints) == 0 {
        return 0
    }
    if len(ints) == 1 {
        return ints[0]
    }
    return op(a, RfoldInt(ints[1:]))
}

// Doesn't
func LfoldInt(op func(a, b int) int, ints ...int) int {
    if len(ints) == 0 {
        return 0
    }
    if len(ints) == 1 {
        return ints[0]
    }
    a = ints[0]
    b = ints[1]
    return Lfold(op(a, b), ints...)
}


What is the expected output?
I would expect the LfoldInt function to compile.

What do you see instead?
Compiler prints:
too many arguments in call to LfoldInt

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Linux

Which revision are you using?  (hg identify)
9f2be4fbbf69 weekly/weekly.2012-01-20


Please provide any additional information below.
God speed!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions