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: the Graph example doesn't compile #39734

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

cmd/go2go: the Graph example doesn't compile #39734

TapirLiu opened this issue Jun 21, 2020 · 3 comments

Comments

@TapirLiu
Copy link
Contributor

@TapirLiu TapirLiu commented Jun 21, 2020

What did you do?

code: https://go2goplay.golang.org/p/6EKNV4FQ4KI

What did you expect to see?

Compiles

What did you see instead?

Doesn't compile

BTW, is type (v *Vertex) Edges() []*FromTo { ... } a typo of func (v *Vertex) Edges() []*FromTo { ... }

@arl
Copy link
Contributor

@arl arl commented Jun 21, 2020

I'm not saying it's normal, but if you want to make the example compile you need provide explicit type parameters when instantiating Graph:

g := New(*Vertex, *FromTo)([]*Vertex{}) // ok

Also, while I understand the error message for:

g := New(Vertex, *FromTo)([]*Vertex{}) // error: *Vertex does not satisfy NodeConstraint(Edge) (missing method Edges)

I'm not sure I understand why it says the same thing in the following case, since the Vertex type parameter is now correct:

g := New(*Vertex, FromTo)([]*Vertex{}) // error: Vertex does not satisfy NodeConstraint(Edge) (missing method Edges)

Or maybe is it because there's a mismatch for the 1st type parameter, between Vertex (inferred from FromTo) and *Vertex?

@TapirLiu
Copy link
Contributor Author

@TapirLiu TapirLiu commented Jun 21, 2020

OK, but maybe it is possible to deduce the Edge type as *FromTo from the New([]*Vertex{}) call, for *Vertex has a Edges() []*FromTo method.

@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Jun 29, 2020

This seems like a question which has been answered.

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
3 participants
You can’t perform that action at this time.