Skip to content

valast: use generics instead of valast.Addr #42

@bobheadxi

Description

@bobheadxi

Right now the generated assertions for some pointer types use valast.Addr to get an interface{} that then gets cast back into the desired type. It's quite a lot of casting around for certain types like *int32, which generates:

autogold.Expect(valast.Addr(int32(12)).(*int32)).Equal(...)

With generics, this can be:

func Addr[T any](v T) *T { return &v }

autogold.Expect(valast.Addr(int32(12))).Equal(...)

The improvement is nicer for simpler types, where before:

valast.Addr("device-1").(*string)

with generics:

valast.Addr("device-1")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions