bflad / tfproviderlint

Terraform Provider Lint Tool
Mozilla Public License 2.0
134 stars 25 forks source link

tfproviderlint crashes on go1.22 #298

Closed remyleone closed 3 months ago

remyleone commented 4 months ago

https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540

tfproviderlint -R014=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...
  shell: /usr/bin/bash -e {0}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x59796f]

goroutine [3](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:3)529 [running]:
go/types.(*Checker).handleBailout(0xc0009e2[4](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:5)00, 0xc00194fbd0)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/check.go:367 +0x88
panic({0x739280?, 0x9ea920?})
    /opt/hostedtoolcache/go/1.22.2/x64/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0x812[5](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:6)70, 0x9ee620})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/sizes.go:228 +0x30f
go/types.(*Config).sizeof(...)
    /opt/hostedtoolcache/go/1.22.2/x[6](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:7)4/src/go/types/sizes.go:333
go/types.representableConst.func1({0x812570?, 0x9ee620?})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/const.go:[7](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:8)6 +0x9e
go/types.representableConst({0x[8](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:9)14218, 0x9e2fc0}, 0xc0009e2400, 0x[9](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:10)ee620, 0xc00194d908)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc0009e2400, 0xc000252a80, 0x9ee620)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc0009e2400, 0xc000252a80, {0x812570, 0x9ee620})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/expr.go:375 +0x2d7
go/types.(*Checker).assignment(0xc0009e2400, 0xc000252a80, {0x812570, 0x9ee620}, {0x78f20a, 0xa})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/assignments.go:52 +0x2e5
go/types.(*Checker).initVar(0xc0009e2400, 0xc0019464e0, 0xc000252a80, {0x78f20a, 0xa})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/assignments.go:163 +0x3b2
go/types.(*Checker).initVars(0xc0009e2400, {0xc001494428, 0x1, 0x0?}, {0xc0004e47a0, 0xc001929140?, 0x4eecec?}, {0x0, 0x0})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/assignments.go:382 +0x638
go/types.(*Checker).shortVarDecl(0xc0009e2400, {0x811440, 0xc00063c0f0}, {0xc0004e4790, 0x1, 0x811dc0?}, {0xc0004e47a0, 0x1, 0x1})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/assignments.go:556 +0x8f0
go/types.(*Checker).stmt(0xc0009e2400, 0x0, {0x813a78, 0xc000339400})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/stmt.go:473 +0x15ff
go/types.(*Checker).simpleStmt(...)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/stmt.go:99
go/types.(*Checker).stmt(0xc0009e2400, 0x0, {0x813ce8, 0xc000339480})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/stmt.go:805 +0x21b8
go/types.(*Checker).stmtList(0xc0009e2400, 0x0, {0xc000339500?, 0xc001907d40?, 0xc001937948?})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/stmt.go:121 +0x85
go/types.(*Checker).funcBody(0xc0009e2400, 0x8126[10](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:11)?, {0xc000e3cb50?, 0xc0004e5000?}, 0xc0002524c0, 0xc000194a20, {0x0?, 0x0?})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/stmt.go:41 +0x331
go/types.(*Checker).funcDecl.func1()
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/decl.go:852 +0x3a
go/types.(*Checker).processDelayed(0xc0009e2400, 0x0)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/check.go:467 +0x162
go/types.(*Checker).checkFiles(0xc0009e2400, {0xc001494228, 0x1, 0x1})
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/check.go:4[11](https://github.com/scaleway/terraform-provider-scaleway/actions/runs/8722750320/job/23929321814?pr=2540#step:5:12) +0x1cc
go/types.(*Checker).Files(...)
    /opt/hostedtoolcache/go/1.22.2/x64/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0xc00016c000, 0xc0008a9620)
    /home/runner/go/pkg/mod/golang.org/x/tools@v0.8.0/go/packages/packages.go:1052 +0xa72
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
    /home/runner/go/pkg/mod/golang.org/x/tools@v0.8.0/go/packages/packages.go:851 +0x1a9
sync.(*Once).doSlow(0x0?, 0x0?)
    /opt/hostedtoolcache/go/1.22.2/x64/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
    /opt/hostedtoolcache/go/1.22.2/x64/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
    /home/runner/go/pkg/mod/golang.org/x/tools@v0.8.0/go/packages/packages.go:839 +0x4a
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
    /home/runner/go/pkg/mod/golang.org/x/tools@v0.8.0/go/packages/packages.go:846 +0x26
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 2883
    /home/runner/go/pkg/mod/golang.org/x/tools@v0.8.0/go/packages/packages.go:845 +0x94
Error: Process completed with exit code 2.
momer commented 3 months ago

Will add more detail when the provider I'm working on becomes public; for now, I can confirm that this is an issue only impacting some providers. This issue was encountered only after implementing a new data source with a Schema as:

func (d *listDataSource) Schema(_ context.Context, _ tfds.SchemaRequest, resp *tfds.SchemaResponse) {
    resp.Schema = dschema.Schema{
        MarkdownDescription: listDataSourceMarkdownDescription,
        Attributes: map[string]dschema.Attribute{
            "plans": dschema.ListNestedAttribute{
                MarkdownDescription: dataSourceMarkdownDescription,
                Computed:            true,
                NestedObject: dschema.NestedAttributeObject{
                    Attributes: schemaAttributes(),
                },
            },
        },
    }
}

Prior to adding this provider, and the rest of its implementation, I only had implemented a few simple providers which ran the linter with no problems!

bflad commented 3 months ago

Thank you for the reports and sorry for the trouble. This tooling is dependent on Go static analysis tooling APIs without the same compatibility as the language itself, so this sort of issue can occur when the Go language is updated. For better or worse, it looks like this is also reproducible with the Go module's unit testing, e.g.

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100ab0874]

goroutine 261 [running]:
go/types.(*Checker).handleBailout(0x14000932600, 0x14000285b98)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/check.go:367 +0x9c
panic({0x100bc9e60?, 0x100da0670?})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x100c16a78, 0x100da3aa0})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/sizes.go:228 +0x314
go/types.(*Config).sizeof(...)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/sizes.go:333
go/types.representableConst.func1({0x100c16a78?, 0x100da3aa0?})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x100c17dc0, 0x100d97d78}, 0x14000932600, 0x100da3aa0, 0x14000283c78)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/const.go:106 +0x2b0
go/types.(*Checker).representation(0x14000932600, 0x14000569dc0, 0x100da3aa0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/const.go:256 +0x68
go/types.(*Checker).representable(0x14000932600, 0x14000569dc0, 0x100da3aa0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/const.go:239 +0x28
go/types.(*Checker).shift(0x14000932600, 0x14000569d40, 0x14000569dc0, {0x100c172b8, 0x140007554d0}, 0x14)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:650 +0x1d8
go/types.(*Checker).binary(0x14000932600, 0x14000569d40, {0x100c172b8, 0x140007554d0}, {0x100c16e08, 0x140000ed500}, {0x100c16e08, 0x140000ed520}, 0x14, 0x9ce)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:796 +0x100
go/types.(*Checker).exprInternal(0x14000932600, 0x0, 0x14000569d40, {0x100c172b8, 0x140007554d0}, {0x0, 0x0})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:1416 +0x1d4
go/types.(*Checker).rawExpr(0x14000932600, 0x0, 0x14000569d40, {0x100c172b8?, 0x140007554d0?}, {0x0?, 0x0?}, 0x0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14000932600, 0x0?, 0x14000569d40, {0x100c172b8?, 0x140007554d0?})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).binary(0x14000932600, 0x14000569d40, {0x100c172b8, 0x14000755500}, {0x100c172b8, 0x140007554d0}, {0x100c16e08, 0x140000ed540}, 0xd, 0x9d2)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:783 +0x70
go/types.(*Checker).exprInternal(0x14000932600, 0x0, 0x14000569d40, {0x100c172b8, 0x14000755500}, {0x0, 0x0})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:1416 +0x1d4
go/types.(*Checker).rawExpr(0x14000932600, 0x0, 0x14000569d40, {0x100c172b8?, 0x14000755500?}, {0x0?, 0x0?}, 0x0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14000932600, 0x14000b3fb60?, 0x14000569d40, {0x100c172b8?, 0x14000755500?})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).constDecl(0x14000932600, 0x14000b3fc20, {0x0, 0x0}, {0x100c172b8, 0x14000755500}, 0x0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/decl.go:488 +0x23c
go/types.(*Checker).objDecl(0x14000932600, {0x100c1a118, 0x14000b3fc20}, 0x0)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/decl.go:191 +0x84c
go/types.(*Checker).packageObjects(0x14000932600)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/resolver.go:693 +0x468
go/types.(*Checker).checkFiles(0x14000932600, {0x140001126a0, 0x1, 0x1})
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0x140001881c0, 0x14000715a70)
        /Users/bflad/src/github.com/bflad/tfproviderlint/vendor/golang.org/x/tools/go/packages/packages.go:1055 +0x870
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
        /Users/bflad/src/github.com/bflad/tfproviderlint/vendor/golang.org/x/tools/go/packages/packages.go:854 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
        /opt/homebrew/Cellar/go/1.22.3/libexec/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
        /Users/bflad/src/github.com/bflad/tfproviderlint/vendor/golang.org/x/tools/go/packages/packages.go:842 +0x50
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
        /Users/bflad/src/github.com/bflad/tfproviderlint/vendor/golang.org/x/tools/go/packages/packages.go:849 +0x30
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 254
        /Users/bflad/src/github.com/bflad/tfproviderlint/vendor/golang.org/x/tools/go/packages/packages.go:848 +0x84
FAIL    github.com/bflad/tfproviderlint/passes/AT001    2.654s

I will take a look today to see how difficult it might be to upgrade those tooling dependences so this Go module can support Go 1.22.

bflad commented 3 months ago

@remyleone thank you for providing the affected repository and command you ran -- after #299, was able to confirm that upgrading golang.org/x/tools to latest seems to have resolved this issue.

terraform-provider-scaleway on  master via 🦫 v1.22.3
❯ ~/go/bin/tfproviderlint -R014=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...

terraform-provider-scaleway on  master via 🦫 v1.22.3 took 15s
❯

Will cut a tfproviderlint v0.30.0 release soon after I take care of some other dependency and GitHub Actions workflow upgrades.