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(gnolang): duplicate field name in struct literal #708

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

tbruyelle
Copy link
Contributor

@tbruyelle tbruyelle commented Apr 6, 2023

Fix #629

Description

The following code returns an error in go, but not in gno:

type s struct {
  f int
}
s{f:1, f:2}

The change detects a field has already been set in a struct literal and panics.

Note that unlike go code, the parsing stops at the first duplicate field met, whereas in go all the duplicate fields are mentionned in the error.

See go playground link: https://go.dev/play/p/byJwYsIETBU

How has this been tested?

A new testfile has been added.

go test ./gnovm//tests/ -v -run 'Files/struct2b'

Fix gnolang#629

The following code returns an error in go, but not in gno:
```go
type s struct {
  f int
}
s{f:1, f:2}
```
The change detects a field has already been set in a struct literal and
panics.

Note that unlike go code, the parsing stops at the first duplicate field
met, whereas in go all the duplicate fields are mentionned in the error.

See go playground link: https://go.dev/play/p/byJwYsIETBU
@tbruyelle tbruyelle requested a review from a team as a code owner April 6, 2023 14:57
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

This is good. However I made a test and seems like this error is not caught also on maps (ie.

	m := map[string][]Foo{
		"hello": {Foo{"foo"}, Foo{"bar"}},
		"world": {Foo{"truc"}, Foo{"machin"}},
		"hello": {},
	}

does not return an error), and I imagine probably array/slices as well.

Shall we address them all in one PR (as they are essentially the same bug), or do you want to tackle this in a different PR?

@moul
Copy link
Member

moul commented Apr 18, 2023

Shall we address them all in one PR (as they are essentially the same bug), or do you want to tackle this in a different PR?

@tbruyelle up to you.

@tbruyelle
Copy link
Contributor Author

Good catch @thehowl !
Let's address that in an other PR. Can you create an issue ?

@moul moul merged commit c33bb32 into gnolang:master Apr 18, 2023
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Archived in project
Development

Successfully merging this pull request may close these issues.

parsing - struct can have double definitions of value
3 participants