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

regexpSimplify gives an incorrect simplification for (foo|). #1418

Open
csilvers opened this issue May 15, 2024 · 0 comments
Open

regexpSimplify gives an incorrect simplification for (foo|). #1418

csilvers opened this issue May 15, 2024 · 0 comments

Comments

@csilvers
Copy link

For this file:

package test
import "regexp"
var _ = regexp.MustCompile(`(a|)`)

gocritic gives this output:

% go run github.com/go-critic/go-critic/cmd/gocritic@latest check --enable '#style' /tmp/test.go
/tmp/test.go:5:28: regexpSimplify: can re-write `(a|)` as `(|?)`

The simplification presumably was meant to be (a)?.

Another example is the string (?:\.(\d+)|), which gocritic wants to simplify to (?:|?). Which may give some idea about what it's matching incorrectly here.

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

1 participant