Skip to content

Commit

Permalink
revert: deref changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev committed Jan 27, 2025
1 parent 846b310 commit 9827937
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
19 changes: 0 additions & 19 deletions internal/deref/deref.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,9 @@ func Type(t reflect.Type) reflect.Type {
if t == nil {
return nil
}

// Preserve interface types immediately to maintain type information
// This handles both empty (interface{}) and non-empty (e.g., io.Reader) interfaces
if t.Kind() == reflect.Interface {
return t
}

// Iteratively unwrap pointer types until we reach a non-pointer
// or encounter an interface type that needs preservation
for t.Kind() == reflect.Ptr {
t = t.Elem()
if t == nil {
return nil
}
// Stop unwrapping if we hit an interface type to preserve its type information
// This ensures interface method sets are not lost
if t.Kind() == reflect.Interface {
return t
}
}

// Return the final unwrapped type, which could be any non-pointer, non-interface type
return t
}

Expand Down
17 changes: 0 additions & 17 deletions internal/deref/deref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ func TestType_nil(t *testing.T) {
assert.Nil(t, deref.Type(nil))
}

func TestType_interface_wrapped_pointer(t *testing.T) {
t.Run("one level", func(t *testing.T) {
str := "hello"
var iface any = &str
dt := deref.Type(reflect.TypeOf(iface))
assert.Equal(t, reflect.String, dt.Kind())
})

t.Run("two levels", func(t *testing.T) {
str := "hello"
strPtr := &str
var iface any = &strPtr
dt := deref.Type(reflect.TypeOf(iface))
assert.Equal(t, reflect.String, dt.Kind())
})
}

func TestValue(t *testing.T) {
a := uint(42)
b := &a
Expand Down

0 comments on commit 9827937

Please sign in to comment.