Skip to content

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

@zapateo

Description

@zapateo

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",
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvalidBehaviorA valid or not valid code has an invalid behavior at runtimebugBug: something already implemented does not work as it shouldneedsInvestigationNeed to investigatetemplatesRelated to the template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions