You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the type assertion result is used multiple times inside the switch cases. To make the code cleaner and more efficient, we could assign the result of the type assertion to a variable once and then use that variable inside the switch. This would eliminate the need for multiple type assertions.
The staticcheck tool also reports this issue:
pkg/dsl/compiler/compiler.go:49:10: assigning the result of this type assertion to a variable (switch statement := statement.(type)) could eliminate type assertions in switch cases (S1034)
pkg/dsl/compiler/compiler.go:52:27: could eliminate this type assertion
pkg/dsl/compiler/compiler.go:68:25: could eliminate this type assertion
If you agree with this suggestion, I'd be happy to take care of the fix. Please feel free to assign the issue to me!
Thanks!
Note: even if we keep the assertions in the switch cases, we don't need the ok check (v, ok := s.(type)). We can simplify this to just v := s.(type) since the assertion is already performed. So for example, this check will never evaluate to true, since ok is always true: link to code at line 53. But anyway, assigning the result of the type assertion to a variable will eliminate the need for both, we will no longer need to do type assertions again in switch cases.
The text was updated successfully, but these errors were encountered:
Hi Permify team,
I recently discovered your project, and it looks very promising!
I'm interested in contributing and have started exploring the code.
While reviewing the
Compile
function inpkg/dsl/compiler/compiler.go
, I noticed an opportunity for improvement regarding type assertions.In this section: link to code at line 49
Currently, the type assertion result is used multiple times inside the
switch
cases. To make the code cleaner and more efficient, we could assign the result of the type assertion to a variable once and then use that variable inside theswitch
. This would eliminate the need for multiple type assertions.The
staticcheck
tool also reports this issue:If you agree with this suggestion, I'd be happy to take care of the fix. Please feel free to assign the issue to me!
Thanks!
Note: even if we keep the assertions in the
switch
cases, we don't need theok
check (v, ok := s.(type)
). We can simplify this to justv := s.(type)
since the assertion is already performed. So for example, this check will never evaluate totrue
, sinceok
is alwaystrue
: link to code at line 53. But anyway, assigning the result of the type assertion to a variable will eliminate the need for both, we will no longer need to do type assertions again inswitch cases
.The text was updated successfully, but these errors were encountered: