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

Invalid swapping of elements in slice within a global slice #945

Open
zapateo opened this issue Jun 12, 2023 · 1 comment
Open

Invalid swapping of elements in slice within a global slice #945

zapateo opened this issue Jun 12, 2023 · 1 comment
Labels
bug Bug: something already implemented does not work as it should InvalidBehavior A valid or not valid code has an invalid behavior at runtime needsInvestigation Need to investigate templates Related to the template

Comments

@zapateo
Copy link
Member

zapateo commented Jun 12, 2023

Description

The swapping of the first and the second elements of a slice, which is assigned to a field of a struct of a (global) slice element, generates an invalid behavior.

How to reproduce

Add this test to test/misc/templates_test.go:

"https://github.com/open2b/scriggo/issues/945": {
	sources: fstest.Files{
		"index.txt": `
		{%%
			for item in items {
				item.Options[0], item.Options[1] = item.Options[1], item.Options[0]
				show item.Options[0].Name, ",", item.Options[1].Name
			}
		%%}
		`,
	},
	main: native.Package{
		Name: "main",
		Declarations: native.Declarations{
			"items": &[]struct {
				Options []struct {
					Name string
				}
			}{
				{Options: []struct{ Name string }{
					{Name: "first-option"},
					{Name: "second-option"},
				}},
			},
		},
	},
	expectedOut: "\nsecond-option,first-option\t\t\t",
},
@zapateo zapateo added bug Bug: something already implemented does not work as it should templates Related to the template InvalidBehavior A valid or not valid code has an invalid behavior at runtime needsInvestigation Need to investigate labels Jun 12, 2023
@zapateo
Copy link
Member Author

zapateo commented Jun 12, 2023

@maisola-work this is the issue you encountered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug: something already implemented does not work as it should InvalidBehavior A valid or not valid code has an invalid behavior at runtime needsInvestigation Need to investigate templates Related to the template
Projects
None yet
Development

No branches or pull requests

1 participant