Skip to content

cmd/compile: miscompilation of comparison between type parameter and interface #51522

Closed
@mdempsky

Description

@mdempsky

The program below should run quietly, but instead it prints:

FAIL: if i != t
FAIL: switch i
FAIL: switch t

Marking as a release blocker, because this seems like a miscompilation bug that users could plausibly actually run into. But I think it might be reasonable to punt fixing it to a point release.

A possible workaround here is to replace each use of t with any(t).

package main

func f[T comparable](i any) {
	var t T

	if i != t {
		println("FAIL: if i != t")
	}

	switch i {
	case t:
		// ok
	default:
		println("FAIL: switch i")
	}

	switch t {
	case i:
		// ok
	default:
		println("FAIL: switch t")
	}
}

func main() {
	f[int](int(0))
}

/cc @griesemer @ianlancetaylor @randall77

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions