cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 127 forks source link

Invalid code generated #15

Closed dynamix closed 6 years ago

dynamix commented 8 years ago

If I have something like the following and replace X with int

type _X_ generic.Type

type Cell_X_ struct {
    Value int
}

func m(_X_) {}

func example() {
    a := Cell_X_{}
    m(Cell_X_{})
}

The following code which wont compile is generated.

type CellInt struct {
    Value int
}

func m(int) {}

func example() {
    a := CellInt{}
    m(Cellint{})
}

Is this a limitation in how genny works or a bug?

matryer commented 8 years ago

Looks like a bug in your code. Shouldn't the argument to m be CellX? And shouldn't the value of Value be X?

Sent from my iPhone

On 12 Oct 2015, at 19:15, Martin Karlsch notifications@github.com wrote:

If I have something like the following and replace X with int

type X generic.Type

type CellX struct { Value int }

func m(X) {}

func example() { a := CellX{} m(CellX{}) }

The following code which wont compile is generated.

type CellInt struct { Value int }

func m(int) {}

func example() { a := CellInt{} m(Cellint{}) } Is this a limitation in how genny works or a bug?

— Reply to this email directly or view it on GitHub.

dynamix commented 8 years ago

You are right, the example was not entirely correct ... should be.

type _X_ generic.Type

type Cell_X_ struct {
    Value _X_
}

func m(p Cell_X_) {}

func example() {
    a := Cell_X_{}
    m(Cell_X_{})
}

leads to

package main

type CellInt struct {
    Value int
}

func m(p CellInt) {}

func example() {
    a := CellInt{}
    m(Cellint{})
}

The issue is the same. The CellX passed to m has a lower case "i" whereas the rest has an uppercase "I".

pdrum commented 6 years ago

It's almost the same as https://github.com/cheekybits/genny/issues/49 and https://github.com/cheekybits/genny/issues/36. Will be fixed in the next release.

pdrum commented 6 years ago

Fixed in https://github.com/cheekybits/genny/pull/52