@@ -160,26 +160,42 @@ func (i InMemoryProvider) find(flag string) (*InMemoryFlag, *openfeature.Provide
160160// It coerces smaller numeric types to their canonical forms (int* -> int64, float32 -> float64)
161161// to provide a more forgiving API for test flag configuration.
162162func genericResolve [T comparable ](value any , defaultValue T , detail * openfeature.ProviderResolutionDetail ) T {
163- // Coerce smaller numeric types to canonical forms
164- switch v := value .(type ) {
165- case int :
166- value = int64 (v )
167- case int8 :
168- value = int64 (v )
169- case int16 :
170- value = int64 (v )
171- case int32 :
172- value = int64 (v )
173- case float32 :
174- value = float64 (v )
175- }
176-
177- v , ok := value .(T )
178-
179- if ok {
163+ // Try direct type assertion first
164+ if v , ok := value .(T ); ok {
180165 return v
181166 }
182167
168+ // Handle type conversions based on target type
169+ switch any (defaultValue ).(type ) {
170+ case int64 :
171+ // Convert various int types to int64
172+ switch v := value .(type ) {
173+ case int8 :
174+ return any (int64 (v )).(T )
175+ case int16 :
176+ return any (int64 (v )).(T )
177+ case int32 :
178+ return any (int64 (v )).(T )
179+ case int :
180+ return any (int64 (v )).(T )
181+ }
182+ case float64 :
183+ // Convert float32 to float64 and int types to float64
184+ switch v := value .(type ) {
185+ case float32 :
186+ return any (float64 (v )).(T )
187+ case int8 :
188+ return any (float64 (v )).(T )
189+ case int16 :
190+ return any (float64 (v )).(T )
191+ case int32 :
192+ return any (float64 (v )).(T )
193+ case int :
194+ return any (float64 (v )).(T )
195+ }
196+ }
197+
198+ // If no conversion worked, return error
183199 detail .Reason = openfeature .ErrorReason
184200 detail .ResolutionError = openfeature .NewTypeMismatchResolutionError ("incorrect type association" )
185201 return defaultValue
0 commit comments