Skip to content

Fix import generic function specification#3

Open
Kolterdyx wants to merge 2 commits intosublee:mainfrom
EliumDigitalData:fix-import-generic-function-specification
Open

Fix import generic function specification#3
Kolterdyx wants to merge 2 commits intosublee:mainfrom
EliumDigitalData:fix-import-generic-function-specification

Conversation

@Kolterdyx
Copy link
Copy Markdown

@Kolterdyx Kolterdyx commented Mar 24, 2026

This PR adds support for using generic function instances, fixing #2.

I modified the tailIdent function to not skip over the type params when checking for the last identifier

This allows importing the same generic function multiple times with different type parameters:

main.go

package main

type A struct {
	Value int
}

type B struct {
	Value int
}

func Identity[T any](x T) T {
	return x
}

func main() {}

convgen.go

//go:build convgen

package main

import (
	"github.com/sublee/convgen"
)

var mod = convgen.Module(
	convgen.ImportFunc(Identity[int]),
	convgen.ImportFunc(Identity[string]),
)

var A2B = convgen.Struct[A, B](mod)

Result from above:

//go:build !convgen

// Code generated by github.com/sublee/convgen@dev. DO NOT EDIT.
//
package main

// convgen: explicit converters

func A2B(in A) (out B) {
	// A.Value -> B.Value
	{
		out.Value = Identity[int](in.Value)
	}
	return
}

@Kolterdyx Kolterdyx force-pushed the fix-import-generic-function-specification branch from 4986a11 to 09cadb6 Compare March 24, 2026 22:35
@Kolterdyx
Copy link
Copy Markdown
Author

force push was squashing my commits together into one single change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant