<feed xmlns='http://www.w3.org/2005/Atom'>
<title>godefererr, branch master</title>
<subtitle>Analyser that reports incorrectly returned errors from defer closures</subtitle>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/'/>
<entry>
<title>Increase version v0.0.1 -&gt; v0.0.2</title>
<updated>2024-03-10T16:35:02+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2024-03-10T16:35:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=406135a162e765d1014c6a7e92143e3d034046a1'/>
<id>406135a162e765d1014c6a7e92143e3d034046a1</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>go.mod: Upgrade 'golang.org/x/tools' to latest v0.19.0</title>
<updated>2024-03-10T16:32:37+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2024-03-10T16:27:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=e29476943fcb9ea964795ea6d782bc41a0f33aa6'/>
<id>e29476943fcb9ea964795ea6d782bc41a0f33aa6</id>
<content type='text'>
After upgrading to Go 1.22.0, I ended up with a segfault:

    $ go test -v
    === RUN   Test
    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=0x1006fef14]

    goroutine 44 [running]:
    go/types.(*Checker).handleBailout(0x140003e8c00, 0x14000027b98)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:367 +0x9c
    panic({0x100815520?, 0x1009e85d0?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/panic.go:770 +0x124
    go/types.(*StdSizes).Sizeof(0x0, {0x100861ca8, 0x1009eb9a0})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/sizes.go:228 +0x314
    go/types.(*Config).sizeof(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/sizes.go:333
    go/types.representableConst.func1({0x100861ca8?, 0x1009eb9a0?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/const.go:76 +0x9c
    go/types.representableConst({0x100862fb0, 0x1009dfd60}, 0x140003e8c00, 0x1009eb9a0, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/const.go:92 +0x138
    go/types.(*Checker).arrayLength(0x140003e8c00, {0x100862088, 0x140002f5c00?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:510 +0x238
    go/types.(*Checker).typInternal(0x140003e8c00, {0x100862058, 0x140003f6a80}, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:299 +0x3bc
    go/types.(*Checker).definedType(0x140003e8c00, {0x100862058, 0x140003f6a80}, 0x14000027158?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:180 +0x2c
    go/types.(*Checker).varType(0x140003e8c00, {0x100862058, 0x140003f6a80})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:145 +0x2c
    go/types.(*Checker).structType(0x140003e8c00, 0x140003f6de0, 0x140003f6de0?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/struct.go:113 +0x128
    go/types.(*Checker).typInternal(0x140003e8c00, {0x100862328, 0x1400000d368}, 0x140004220a0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:316 +0xed0
    go/types.(*Checker).definedType(0x140003e8c00, {0x100862328, 0x1400000d368}, 0x10052c214?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:180 +0x2c
    go/types.(*Checker).typeDecl(0x140003e8c00, 0x140004220a0, 0x140003bd940, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/decl.go:615 +0x39c
    go/types.(*Checker).objDecl(0x140003e8c00, {0x100865178, 0x140004220a0}, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/decl.go:197 +0x880
    go/types.(*Checker).packageObjects(0x140003e8c00)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/resolver.go:681 +0x3c0
    go/types.(*Checker).checkFiles(0x140003e8c00, {0x14000052660, 0x1, 0x1})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:408 +0x164
    go/types.(*Checker).Files(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:372
    golang.org/x/tools/go/packages.(*loader).loadPackage(0x140001581c0, 0x14000169230)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:1052 +0x870
    golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:851 +0x178
    sync.(*Once).doSlow(0x0?, 0x0?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/sync/once.go:74 +0x100
    sync.(*Once).Do(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/sync/once.go:65
    golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:839 +0x50
    golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:846 +0x30
    created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 43
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:845 +0x84
    exit status 2
    FAIL	gopkg.teddywing.com/defererr	0.130s

Upgrading to the latest version of 'golang.org/x/tools' resolved the
problem.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
After upgrading to Go 1.22.0, I ended up with a segfault:

    $ go test -v
    === RUN   Test
    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=0x1006fef14]

    goroutine 44 [running]:
    go/types.(*Checker).handleBailout(0x140003e8c00, 0x14000027b98)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:367 +0x9c
    panic({0x100815520?, 0x1009e85d0?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/runtime/panic.go:770 +0x124
    go/types.(*StdSizes).Sizeof(0x0, {0x100861ca8, 0x1009eb9a0})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/sizes.go:228 +0x314
    go/types.(*Config).sizeof(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/sizes.go:333
    go/types.representableConst.func1({0x100861ca8?, 0x1009eb9a0?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/const.go:76 +0x9c
    go/types.representableConst({0x100862fb0, 0x1009dfd60}, 0x140003e8c00, 0x1009eb9a0, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/const.go:92 +0x138
    go/types.(*Checker).arrayLength(0x140003e8c00, {0x100862088, 0x140002f5c00?})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:510 +0x238
    go/types.(*Checker).typInternal(0x140003e8c00, {0x100862058, 0x140003f6a80}, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:299 +0x3bc
    go/types.(*Checker).definedType(0x140003e8c00, {0x100862058, 0x140003f6a80}, 0x14000027158?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:180 +0x2c
    go/types.(*Checker).varType(0x140003e8c00, {0x100862058, 0x140003f6a80})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:145 +0x2c
    go/types.(*Checker).structType(0x140003e8c00, 0x140003f6de0, 0x140003f6de0?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/struct.go:113 +0x128
    go/types.(*Checker).typInternal(0x140003e8c00, {0x100862328, 0x1400000d368}, 0x140004220a0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:316 +0xed0
    go/types.(*Checker).definedType(0x140003e8c00, {0x100862328, 0x1400000d368}, 0x10052c214?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/typexpr.go:180 +0x2c
    go/types.(*Checker).typeDecl(0x140003e8c00, 0x140004220a0, 0x140003bd940, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/decl.go:615 +0x39c
    go/types.(*Checker).objDecl(0x140003e8c00, {0x100865178, 0x140004220a0}, 0x0)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/decl.go:197 +0x880
    go/types.(*Checker).packageObjects(0x140003e8c00)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/resolver.go:681 +0x3c0
    go/types.(*Checker).checkFiles(0x140003e8c00, {0x14000052660, 0x1, 0x1})
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:408 +0x164
    go/types.(*Checker).Files(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/go/types/check.go:372
    golang.org/x/tools/go/packages.(*loader).loadPackage(0x140001581c0, 0x14000169230)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:1052 +0x870
    golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:851 +0x178
    sync.(*Once).doSlow(0x0?, 0x0?)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/sync/once.go:74 +0x100
    sync.(*Once).Do(...)
      /opt/homebrew/Cellar/go/1.22.1/libexec/src/sync/once.go:65
    golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:839 +0x50
    golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:846 +0x30
    created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 43
      go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:845 +0x84
    exit status 2
    FAIL	gopkg.teddywing.com/defererr	0.130s

Upgrading to the latest version of 'golang.org/x/tools' resolved the
problem.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add license (GNU GPLv3+)</title>
<updated>2023-05-26T19:35:59+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-26T19:35:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=73574b844ef08e52940c16f4bf8f18f06a2796fe'/>
<id>73574b844ef08e52940c16f4bf8f18f06a2796fe</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add README</title>
<updated>2023-05-26T19:26:45+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-26T19:26:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=15b6d6ae795fdf95352ee17bbd5160a707995f7e'/>
<id>15b6d6ae795fdf95352ee17bbd5160a707995f7e</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add package documentation</title>
<updated>2023-05-26T18:09:36+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-26T18:09:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=7e7367c145b9ac3740ee51bc8cf509948138aa8b'/>
<id>7e7367c145b9ac3740ee51bc8cf509948138aa8b</id>
<content type='text'>
Tried the sample code and it looks like the `return err` is not
necessary. The `err` set in `defer` does work find even when using
`return nil`. Oh well, we can adjust that check later if needed.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Tried the sample code and it looks like the `return err` is not
necessary. The `err` set in `defer` does work find even when using
`return nil`. Oh well, we can adjust that check later if needed.
</pre>
</div>
</content>
</entry>
<entry>
<title>functionState: Format fields after doc comment addition</title>
<updated>2023-05-25T23:24:45+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-25T23:24:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=ec52bd27685fef75ffe76333989760f3cf551743'/>
<id>ec52bd27685fef75ffe76333989760f3cf551743</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add more detail to the explanation of how the analyser works</title>
<updated>2023-05-25T19:25:52+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-25T19:25:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=00707a7693c67076898556f2f5de2c8db46a0463'/>
<id>00707a7693c67076898556f2f5de2c8db46a0463</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>checkErrorAssignedInDefer: Remove obsolete TODO</title>
<updated>2023-05-25T18:48:59+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-25T18:48:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=775991e6a57fddfd69f1cae4d0aee9c234855286'/>
<id>775991e6a57fddfd69f1cae4d0aee9c234855286</id>
<content type='text'>
Since we don't want to bother with functions that return multiple
values, don't actually report a suggested return signature replacement.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since we don't want to bother with functions that return multiple
values, don't actually report a suggested return signature replacement.
</pre>
</div>
</content>
</entry>
<entry>
<title>shouldDeclareErrInSignature: Add note about variable declaration line</title>
<updated>2023-05-25T18:47:05+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-25T18:47:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=8102c9e6fe7e12d625718e362abb29bf1ecdb13c'/>
<id>8102c9e6fe7e12d625718e362abb29bf1ecdb13c</id>
<content type='text'>
When I was first coming up with ideas for the project, I thought that
this line is one I might need to report a diagnostic for, but since the
compiler will catch it, we don't need to bother.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When I was first coming up with ideas for the project, I thought that
this line is one I might need to report a diagnostic for, but since the
compiler will catch it, we don't need to bother.
</pre>
</div>
</content>
</entry>
<entry>
<title>Report missing signature declaration with multiple return values</title>
<updated>2023-05-25T18:40:08+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2023-05-25T18:40:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/godefererr/commit/?id=8bcef611f794272203e05e207259ac8d45d558fb'/>
<id>8bcef611f794272203e05e207259ac8d45d558fb</id>
<content type='text'>
The previous message which reported when a function's return signature
didn't declare an error variable didn't work for functions with multiple
return values.

I thought about extending it and coming up with generated variable names
for the non-error types to be able to support automatic fixing, but this
idea ended up being too complicated. Also, I didn't like the idea of an
automated fixer coming up with generated variable names, because you'd
need to manually rename them anyway. That kind of defeats the purpose of
it being automated.

Instead, change the diagnostic message to only refer to the error
variable and recommend what the declared variable name should be based
on the identifier the error was assigned to in the defer.

Modify our multiple return value test functions according to this new
approach.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The previous message which reported when a function's return signature
didn't declare an error variable didn't work for functions with multiple
return values.

I thought about extending it and coming up with generated variable names
for the non-error types to be able to support automatic fixing, but this
idea ended up being too complicated. Also, I didn't like the idea of an
automated fixer coming up with generated variable names, because you'd
need to manually rename them anyway. That kind of defeats the purpose of
it being automated.

Instead, change the diagnostic message to only refer to the error
variable and recommend what the declared variable name should be based
on the identifier the error was assigned to in the defer.

Modify our multiple return value test functions according to this new
approach.
</pre>
</div>
</content>
</entry>
</feed>
