Overriding a factory method doesn't affect any, scalar, integer, number

Abierto
#21 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Start with tt.go:155-198 and trace how GetIntegerConverter, GetNumberConverter, GetAnyConverter, and GetScalarConverter build their converters; compare that with the README's factory customization guidance. Use the reproduction in the issue to verify the behavior. Done means either factory overrides affect the composite converters as expected, or the README clearly documents the limitation.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Reproduction snippets assume:

fac := tupleconv.MakeStringToTTConvFactory()

Where: GetIntegerConverter, GetNumberConverter, GetAnyConverter, GetScalarConverter (tt.go:155-198).

The README suggests customizing StringToTTConvFactory by embedding it and overriding methods. Go has no virtual dispatch through embedding: inside GetAnyConverter and GetScalarConverter, fac is the embedded StringToTTConvFactory, so they call its own methods, not the overrides. GetIntegerConverter and GetNumberConverter don't call the factory methods at all; they build MakeStringTo*Converter directly, so an overridden GetUnsignedConverter or GetDoubleConverter is ignored too.

Reproduction:

type myFactory struct{ tupleconv.StringToTTConvFactory }

func (myFactory) GetNumberConverter() tupleconv.Converter[string, any] {
	return tupleconv.MakeFuncConverter(func(s string) (any, error) {
		return "custom number", nil
	})
}

for _, typ := range []tupleconv.TypeName{
	tupleconv.TypeNumber, tupleconv.TypeAny, tupleconv.TypeScalar,
} {
	c, _ := tupleconv.GetConverterByType[string](myFactory{fac}, typ)
	v, _ := c.Convert("1")
	fmt.Printf("%s: %T(%v)\n", typ, v, v)
}
number: string(custom number)
any: uint64(1)
scalar: uint64(1)

Suggested fix: build the composite converters from a TTConvFactory value, e.g. free functions MakeAnyConverter(fac TTConvFactory[string]) used by GetConverterByType, so overrides apply. If the API should stay as it is, document the limitation in the README.

Lenguaje dominante
Go
Estrellas
1
Forks
0
Merge medio
1 h 43 min
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tarantool/go-tupleconv

Todos los issues de tarantool/go-tupleconv

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.