Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: checker panic on embedded pointer to struct field #500

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

sgreben
Copy link
Contributor

@sgreben sgreben commented Dec 18, 2023

Here's a fix for a case I ran into in practice - the checker panics on a valid input:

expression:

(Embed).EmbedPointerEmbedInt > 0

environment:

type Env struct {
	Embed
}
type Embed struct {
	*EmbedPointerEmbed
}

type EmbedPointerEmbed struct {
	EmbedPointerEmbedInt int
}

crash:

panic: reflect: NumField of non-struct type *mock.EmbedPointerEmbed [recovered]
        panic: reflect: NumField of non-struct type *mock.EmbedPointerEmbed

The fix in this PR is to dereference embedded fields until they stop being pointers (see diff in checker/types.go).

@sgreben sgreben changed the title Fix: panic on embedded pointer to struct field Fix: chcker panic on embedded pointer to struct field Dec 18, 2023
@sgreben sgreben changed the title Fix: chcker panic on embedded pointer to struct field Fix: checker panic on embedded pointer to struct field Dec 18, 2023
@antonmedv
Copy link
Member

Let’s also add a rest what evaluation works and we can call a method on EmbeddedPointerStruct.

@sgreben
Copy link
Contributor Author

sgreben commented Dec 18, 2023

^added (passing) tests for eval & method calls

@antonmedv antonmedv merged commit e09a605 into expr-lang:master Dec 18, 2023
8 checks passed
@sgreben sgreben deleted the embedded-pointer-to-struct-field branch December 18, 2023 20:50
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.

None yet

2 participants