Skip to content

Conversation

paulip1792
Copy link
Contributor

@paulip1792 paulip1792 commented Mar 7, 2022

	switch t.Kind() {
	case reflect.Ptr:
		// unwrap pointer
		v = v.Elem()
		t = t.Elem()
		fallthrough

	case reflect.Struct:
		// if its a struct, walk its fields and recurse.
...

Fallthrough will execute the action in next case regardless of the condition.
case reflect.Struct will be executed even if the pointee of a pointer is not a Struct.

package main

import (
	"fmt"
)

func main() {
	eval := func() int {
		fmt.Println("eval")
		return 2
	}
	switch {
	case 1 == 1:
		fmt.Println("1 == 1")
		fallthrough
	case eval() == 1:
		fmt.Println("2 == 1")
	}
}

Output:

1 == 1
2 == 1

Go Playground

Copy link
Contributor

@iand iand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iand iand requested a review from frrist March 7, 2022 16:50
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @paulip1792.

@frrist frrist merged commit 0549483 into filecoin-project:master Mar 7, 2022
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.

3 participants