Skip to content

Use reflect.TypeFor instead of reflect.TypeOf((*T)(nil)).Elem()#4949

Open
pietern wants to merge 1 commit intomainfrom
go1.22-reflect-typefor
Open

Use reflect.TypeFor instead of reflect.TypeOf((*T)(nil)).Elem()#4949
pietern wants to merge 1 commit intomainfrom
go1.22-reflect-typefor

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Apr 13, 2026

Summary

  • Replace the verbose reflect.TypeOf((*T)(nil)).Elem() idiom with reflect.TypeFor[T](), available since Go 1.22
  • Delete the now-redundant calladapt.TypeOf helper
  • Add a ruleguard lint rule to prevent reintroduction

Test plan

  • go build ./...
  • go test for all modified packages
  • golangci-lint run ./... passes
  • Verified lint rule fires on the old pattern

This pull request was AI-assisted by Isaac.

Replace the verbose pre-Go 1.22 idiom with `reflect.TypeFor[T]()`,
added in Go 1.22 (https://go.dev/doc/go1.22#reflect). Delete the
now-redundant `calladapt.TypeOf` helper and add a ruleguard lint
rule to prevent reintroduction of the old pattern.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown

Approval status: pending

/bundle/ - needs approval

Files: bundle/direct/dresources/adapter.go
Suggested: @denik
Also eligible: @shreyas-goenka, @andrewnester, @anton-107, @janniklasrose, @lennartkats-db

General files (require maintainer)

Files: libs/calladapt/calladapt.go, libs/calladapt/calladapt_test.go, libs/calladapt/validate_test.go, libs/dyn/convert/struct_info.go, libs/gorules/rule_reflect_typefor.go, libs/utils/utils.go
Based on git history:

  • @denik -- recent work in bundle/direct/dresources/, libs/dyn/convert/, libs/calladapt/

Any maintainer (@andrewnester, @anton-107, @denik, @shreyas-goenka, @simonfaltum, @renaudhartert-db) can approve all areas.
See OWNERS for ownership rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant