diff --git a/Dockerfile b/Dockerfile index 65746bdde..170d0c699 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile References: https://docs.docker.com/engine/reference/builder/ # Start from the latest golang base image -FROM golang:1.17-alpine as builder +FROM golang:1.18.3-alpine as builder # Set the Current Working Directory inside the container WORKDIR /app diff --git a/generics_other.go b/generics_other.go index a64f6dc9b..a695023b1 100644 --- a/generics_other.go +++ b/generics_other.go @@ -10,81 +10,3 @@ func typeSpecFullName(typeSpecDef *TypeSpecDef) string { func (pkgDefs *PackagesDefinitions) parametrizeStruct(original *TypeSpecDef, fullGenericForm string) *TypeSpecDef { return original } - -func (pkgDefs *PackagesDefinitions) parametrizeStruct(original *TypeSpecDef, fullGenericForm string) *TypeSpecDef { - genericParams := strings.Split(strings.TrimRight(fullGenericForm, "]"), "[") - if len(genericParams) == 1 { - return nil - } - genericParams = strings.Split(genericParams[1], ",") - for i, p := range genericParams { - genericParams[i] = strings.TrimSpace(p) - } - genericParamTypeDefs := map[string]*TypeSpecDef{} - - if len(genericParams) != len(original.TypeSpec.TypeParams.List) { - return nil - } - - for i, genericParam := range genericParams { - tdef, ok := pkgDefs.uniqueDefinitions[genericParam] - if !ok { - return nil - } - genericParamTypeDefs[original.TypeSpec.TypeParams.List[i].Names[0].Name] = tdef - } - - parametrizedTypeSpec := &TypeSpecDef{ - File: original.File, - PkgPath: original.PkgPath, - TypeSpec: &ast.TypeSpec{ - Doc: original.TypeSpec.Doc, - Comment: original.TypeSpec.Comment, - Assign: original.TypeSpec.Assign, - }, - } - - ident := &ast.Ident{ - NamePos: original.TypeSpec.Name.NamePos, - Obj: original.TypeSpec.Name.Obj, - } - genNameParts := strings.Split(fullGenericForm, "[") - if strings.Contains(genNameParts[0], ".") { - genNameParts[0] = strings.Split(genNameParts[0], ".")[1] - } - ident.Name = genNameParts[0] + "[" + strings.Replace(strings.Join(genNameParts[1:], ""), ".", "_", -1) - ident.Name = strings.Replace(strings.Replace(ident.Name, "\t", "", -1), " ", "", -1) - - parametrizedTypeSpec.TypeSpec.Name = ident - - origStructType := original.TypeSpec.Type.(*ast.StructType) - - newStructTypeDef := &ast.StructType{ - Struct: origStructType.Struct, - Incomplete: origStructType.Incomplete, - Fields: &ast.FieldList{ - Opening: origStructType.Fields.Opening, - Closing: origStructType.Fields.Closing, - }, - } - - for _, field := range origStructType.Fields.List { - newField := &ast.Field{ - Doc: field.Doc, - Names: field.Names, - Tag: field.Tag, - Comment: field.Comment, - } - if genTypeSpec, ok := genericParamTypeDefs[field.Type.(*ast.Ident).Name]; ok { - newField.Type = genTypeSpec.TypeSpec.Type - } else { - newField.Type = field.Type - } - - newStructTypeDef.Fields.List = append(newStructTypeDef.Fields.List, newField) - } - - parametrizedTypeSpec.TypeSpec.Type = newStructTypeDef - - return parametrizedTypeSpec -} diff --git a/packages.go b/packages.go index 1c1e3165a..445d09576 100644 --- a/packages.go +++ b/packages.go @@ -134,19 +134,7 @@ func (pkgDefs *PackagesDefinitions) parseTypesFromFile(astFile *ast.File, packag pkgDefs.uniqueDefinitions = make(map[string]*TypeSpecDef) } - fullName := typeSpecDef.FullName() - - if typeSpecDef.TypeSpec.TypeParams != nil { - fullName = fullName + "[" - for i, typeParam := range typeSpecDef.TypeSpec.TypeParams.List { - if i > 0 { - fullName = fullName + "," - } - - fullName = fullName + typeParam.Names[0].Name - } - fullName = fullName + "]" - } + fullName := typeSpecFullName(typeSpecDef) anotherTypeDef, ok := pkgDefs.uniqueDefinitions[fullName] if ok {