Skip to content

Build with go1.25, governer cannot recognize type aliases in // goverter:extend #213

@wufeng5702

Description

@wufeng5702

Describe the bug
some convert function for grpc:

import (
	"time"

	"google.golang.org/protobuf/types/known/timestamppb"
)

// goverter:converter
// goverter:extend TimeToTimestamppb
type ConverterTimeToTimestamppb interface {
	ConverterTimeToTimestamppb(source Input) Output
}

type Input struct {
	Time time.Time
}

type Output struct {
	Time *timestamp.Timestamp
}

// not work
// goverter build with go1.25 cannot recognize `type timestamp.Timestamp = timestamppb.Timestamp`
func TimeToTimestamppb(time time.Time) *timestamppb.Timestamp {
	return timestamppb.New(time)
}

To Reproduce

exec command (it work on goverter with go1.23), I got this:

$ goverter gen -g 'ignoreUnexported yes'  ./convert
Error while creating converter method:
    ./convert/convert.go:19
    func (convert.ConverterTimeToTimestamppb).ConverterTimeToTimestamppb(source convert.Input) convert.Output
        [source] convert.Input
        [target] convert.Output

| convert.Input
|
|      | time.Time
|      |
source.Time .???
target.Time*.Seconds
|      |   | |
|      |   | | int64
|      |   |
|      |   | google.golang.org/protobuf/types/known/timestamppb.Timestamp
|      |
|      | *github.com/golang/protobuf/ptypes/timestamp.Timestamp
|
| convert.Output

Cannot match the target field with the source entry: "Seconds" does not exist.

Expected behavior
recognize type alias.

By the way, I found a solution, change the output type of the function from *timestamppb.Timestamp to *timestamp.Timestamp,

func TimeToTimestamp(time time.Time) *timestamp.Timestamp {
	return timestamppb.New(time)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions