Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go2go: cannot compare v == nil (operator == not defined for T) #39755

Closed
TapirLiu opened this issue Jun 22, 2020 · 3 comments
Closed

cmd/go2go: cannot compare v == nil (operator == not defined for T) #39755

TapirLiu opened this issue Jun 22, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@TapirLiu
Copy link
Contributor

What did you do?

code: https://go2goplay.golang.org/p/8I6v85VgZW2

package main

import (
)

type PathParamsConstraint interface {
        type map[string]string, []struct{key, value string}
}

type PathParams(type T PathParamsConstraint) struct {
	t T
}

func NewPathParams(type T PathParamsConstraint)(t T) *PathParams(T) {
	return &PathParams(T){
		t: t,
	}
}

func (pp *PathParams(T)) Blank() bool {
	return len(pp.t) == 0
}

func (pp *PathParams(T)) IsNil() bool {
	return pp.t == nil // this line doesn't compile
	// cannot compare pp.t == nil (operator == not defined for T)
}

func main() {
}

What did you expect to see?

Compiles

What did you see instead?

Doesn't compile

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 22, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 22, 2020
@ianlancetaylor
Copy link
Contributor

Currently this does not type check.

type checking failed for main
foo.go2:25:9: cannot compare pp.t == nil (operator == not defined for T)

I guess that technically it should pass the type checker.

@gopherbot
Copy link

Change https://golang.org/cl/239338 mentions this issue: [dev.go2go] go/types: implement a few more predicates for type list sums

@griesemer
Copy link
Contributor

Fixed on dev.go2go.

gopherbot pushed a commit that referenced this issue Jun 22, 2020
Also: Don't convert an untyped nil to a type parameter when
checking if an untyped value (nil) can be coverted to a target
type.

Fixes #39755.

Change-Id: Ib2645759dc659b9c80c2d0a457180eb9616c7cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239338
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants