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

Aperta
#21 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
1
Fork
0
Merge medio
1h 43m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tarantool/go-tupleconv

Tutte le issue di tarantool/go-tupleconv

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.