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

Switch fallthrough not supported #920

Open
jonathangjertsen opened this issue Sep 13, 2024 · 3 comments
Open

Switch fallthrough not supported #920

jonathangjertsen opened this issue Sep 13, 2024 · 3 comments

Comments

@jonathangjertsen
Copy link

Describe the bug

Fallthrough statements in switch statements do not exist in the generated go file, instead it just outputs the string "fallthrough".

To Reproduce

package main

templ example(x int) {
	switch x {
        case 0:
            fallthrough
        case 1:
            <p>hey</p>
    }
}

Expected behavior

@example(0) should generate the output <p>hey</p>

templ info output

(✓) os [ goos=windows goarch=amd64 ]
(✓) go [ location=C:\Program Files\Go\bin\go.exe version=go version go1.22.0 windows/amd64 ]
(✓) gopls [ location=C:\Users\jrg\go\bin\gopls.exe version=golang.org/x/tools/gopls v0.16.2 ]
(✓) templ [ location=C:\Users\jrg\go\bin\templ.exe version=v0.2.771 ]
@bcklin
Copy link

bcklin commented Oct 5, 2024

Golang does not perform fall-through in switch statements. See https://go.dev/tour/flowcontrol/9

@jonathangjertsen
Copy link
Author

Golang does not perform fall-through in switch statements. See https://go.dev/tour/flowcontrol/9

Unless you use the fallthrough keyword. 🙂

@a-h
Copy link
Owner

a-h commented Oct 6, 2024

Thanks for the report.

This should be fairly straightforward to sort out. Need to add a parser and node type for it, and a validator to make sure it only appears as a child of the case statement, and that there there are no nodes between the fallthrough and the next case node.

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

No branches or pull requests

3 participants