cheekybits / genny

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

Generates specific type with lower case when it should be capitalized #36

Closed leonsal closed 5 years ago

leonsal commented 7 years ago

The code generated by genny generates the object name (ObjInt) with the specific type in lower case when it should be capitalized. This occurs when the object name is the parameter of new function. Does not occur if preceded by a space:

package dsp

import "github.com/cheekybits/genny/generic"

//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "NumberType=int"

type NumberType generic.Number

type ObjNumberType struct {
    v NumberType
}

func NewNumberType() *ObjNumberType {

    // Works
    //return &{ObjNumberType}

    // Works (there is a space preceding the object name)
    //return new( ObjNumberType)

    // Does not work -> n := new(Objint) (Lowercase Int)
    n := new(ObjNumberType)
    return n
}
icock commented 7 years ago

This also occurs in !FunctionNameSomeThing condition

package slice
import "github.com/cheekybits/genny/generic"

type SomeThing generic.Type

func ContainsSomeThing(slice []Something, element Something) bool {
        // code omitted
    return false
}

func ContainsAllSomeThing(slice []Something, other []Something) bool {
    for _, e := range other {
        if !ContainsSomeThing(slice, e) { // <-- Generates `Containslowercased`
            return false
        }
    }
    return true
}

with SomeThing=string, genny outputs

// ...
func ContainsAllString(slice []Something, other []Something) bool {
    // ...
        if !Containsstring(slice, e) {
        // ...             
}

Changing if !ContainsSomeThing(slice, e) to if ContainsSomeThing(slice, e), genny generates correct code.

deanveloper commented 6 years ago

Also having this issue with the new function... would be extremely useful if this could be fixed

pdrum commented 5 years ago

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