Skip to content

cmd/compile: compiler permits variadic yield functions for range-over-func #78483

@griesemer

Description

@griesemer

The compiler accepts (playground)

package main

import "fmt"

func main() {
	for a := range f {
		fmt.Println(a)
	}
}

func f(yield func(...int) bool) {
	yield(1)
	yield(1, 2)
	yield(1, 2, 3)
}

yet the spec does not explicitly allow this.

It is also confusing because the type of the yield function argument (...int in this case) does not match the type of the iterator variable ([]int in this case).

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions