Skip to content

cmd/compile: incorrect compiler error in for range statement #73491

Closed
@randall77

Description

@randall77
package main

type T int

const K T = 5

type P struct {
	a [K]*byte
}

func f(p *P) {
	for i := range K {
		p.a[i] = nil
	}
}

Fails to compile with the kinda cryptic error:

tmp1.go:12:17: cannot use len(p.a) - 1 (type int) as type T in assignment

This gets triggered when rewriting that loop to a runtime.memclrHasPointers call.
It is trying to compute the final value for i as len(a)-1, when it should really be T(len(a)-1).

This started happening recently and was noticed inside google. Triggered by CL 659317, not sure exactly why that CL is implicated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions