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
Assignees
Milestone

Comments

@TapirLiu
Copy link
Contributor

@TapirLiu TapirLiu commented Jun 22, 2020

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
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 22, 2020

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

@gopherbot gopherbot commented Jun 22, 2020

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

@griesemer griesemer commented Jun 22, 2020

Fixed on dev.go2go.

@griesemer griesemer closed this Jun 22, 2020
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.