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: type aliases #47

Merged
merged 2 commits into from
Dec 16, 2024
Merged

fix: type aliases #47

merged 2 commits into from
Dec 16, 2024

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Dec 13, 2024

Fixes #46

@ldez ldez changed the title fix: generic types aliases fix: types aliases Dec 13, 2024
Copy link
Owner

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

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

Thank you, @ldez

Can I ask you to copy-paste your example from issue in new testcase (pkg/analyzer/testdata/src)? And check change through TDD

Thanks 🙏

@ldez
Copy link
Contributor Author

ldez commented Dec 15, 2024

The examples come from the test cases of golangci-lint, I thought they were here too.

@ldez
Copy link
Contributor Author

ldez commented Dec 15, 2024

They are already inside your repo.

ex:

func m3() (mapAlias, error) {
return nil, nil // want "return both a `nil` error and an invalid value: use a sentinel error instead"
}

func ifaceTypeAliasedExtPkg() (closerAlias, error) {
return nil, nil // want "return both a `nil` error and an invalid value: use a sentinel error instead"
}

@ldez
Copy link
Contributor Author

ldez commented Dec 15, 2024

To reproduce:

  • modify the min Go version inside the go.mod to go1.23.0
  • run the tests
$ go test ./...
?       github.com/Antonboom/nilnil     [no test files]
--- FAIL: TestNilNil (0.93s)
    analysistest.go:614: examples/positive.go:68: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive.go:82: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive_external_types.go:35: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive_own_types.go:34: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
FAIL
FAIL    github.com/Antonboom/nilnil/pkg/analyzer        0.947s
FAIL

I tried to set:

godebug (
    gotypesalias=1
)

with a min Go version 1.22 but this doesn't produce the error.

But the env var approach works:

$ GODEBUG=gotypesalias=1 go test ./...
?       github.com/Antonboom/nilnil     [no test files]
--- FAIL: TestNilNil (0.90s)
    analysistest.go:614: examples/positive.go:68: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive.go:82: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive_external_types.go:35: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
    analysistest.go:614: examples/positive_own_types.go:34: no diagnostic was reported matching "return both a `nil` error and an invalid value: use a sentinel error instead"
FAIL
FAIL    github.com/Antonboom/nilnil/pkg/analyzer        0.917s
FAIL

EDIT: I know why the godebug directive doesn't work inside the go.mod

To override these defaults, starting in Go 1.23, the work module’s go.mod or the workspace’s go.work can list one or more godebug lines:
https://go.dev/doc/godebug

So the godebug directive inside the go.mod doesn't work with go1.22

@ldez ldez changed the title fix: types aliases fix: type aliases Dec 15, 2024
@Antonboom
Copy link
Owner

They are already inside your repo.

Oh, thanks, I completely forgot about it 🤦
Thanks for MR and digging

@Antonboom Antonboom merged commit 5816603 into Antonboom:master Dec 16, 2024
2 of 3 checks passed
@ldez ldez deleted the fix/alias branch December 16, 2024 18:07
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

Successfully merging this pull request may close these issues.

regression with go1.23 and v1.0.0
2 participants