Arnaud,

GODEBUG=gotypesalias=1 was not redundant in my command. It was used to 
suppress go vet error checking.

peter

On Sunday, August 25, 2024 at 5:30:25 PM UTC-4 Arnaud Delobelle wrote:

> Hi Peter,
>
> Thanks for mentioning gotypesalias.  Looking into that, I see that the 
> go1.23 release notes mention that:
>
>     By default, go/types now produces Alias type nodes for type aliases. 
> This behavior can be controlled by the GODEBUG gotypesalias flag. Its 
> default has changed from 0 in Go 1.22 to 1 in Go 1.23.
>
> This is supported by the test below.  By default go vet does not flag the 
> error, but it does if GODEBUG=gotypesalias=0 (so GODEBUG=gotypesalias=1 was 
> redundant in your command)
>
> ❯ go version
> go version go1.23.0 darwin/arm64
> echo $GODEBUG
>
> ❯ go vet sample.go
> ❯ GODEBUG=gotypesalias=0 go vet sample.go
> # command-line-arguments
> # [command-line-arguments]
> vet: ./sample.go:15:4: invalid use of type alias B in recursive type (see 
> go.dev/issue/50729)
>
> However on the Go playground go vet reports the error (
> https://go.dev/play/p/fjy9259UHPY).  Does this mean that the Go 
> playground is configured with GODEBUG=gotypesalias=0? Is that not an issue 
> with the Go playground?  I think the Go playground should give output 
> consistent with a local installation.
>
> Also it seems that gopls flags this error too by default, even though go 
> vet no longer does.  This also appears to me to be an issue, though a lot 
> harder to diagnose because I can only observe the outcome via the black box 
> of vscode (or another editor configured with gopls).  I do not know how to 
> run gopls as a standalone tool on a file (I do not even know if such a 
> thing is possible).
>
> -- 
> Arnaud
>
> On Sun, 25 Aug 2024 at 18:10, peterGo <go.pe...@gmail.com> wrote:
>
>> Arnaud,
>>
>> $ go version && go run alias.go && go vet alias.go
>> go version devel go1.24-96d8ff00c2 Sat Aug 24 00:51:40 2024 +0000 
>> linux/amd64
>> b = {X:0xc00011c190 Y:0xc00011c1a0}
>> $ 
>>
>> Or
>>
>> $ go1.23 version && go1.23 run alias.go && GODEBUG=gotypesalias=1 go1.23 
>> vet alias.go
>> go version go1.23.0 linux/amd64
>> b = {X:0xc0000141c0 Y:0xc0000141d0}
>> $
>>
>> peter
>>
>> On Saturday, August 24, 2024 at 5:37:20 PM UTC-4 Arnaud Delobelle wrote:
>>
>>> Hi all
>>>
>>> I ran into this error with generic types.  Here is the sample program 
>>> below, which is my best effort to boil it down to its simplest expression.
>>>
>>> I can build and run the program fine with go 1.23.0.  However, on line 
>>> 15 vscode reports the error I put in the comment on that line. I do not 
>>> know how to determine what tool is instructing vscode to report this error 
>>> (I imagine it's gopls but I have no proof).
>>>
>>> package main
>>>
>>> import "fmt"
>>>
>>> func main() {
>>> b := B{X: &A1{X: B{}}, Y: &A2{X: B{}}}
>>> fmt.Printf("b = %#v", b)
>>> }
>>>
>>> type A1 struct {
>>> X B
>>> }
>>>
>>> type A2 struct {
>>> X B // invalid use of type alias B in recursive type (see 
>>> go.dev/issue/50729)compilerInvalidDeclCycle
>>> }
>>>
>>> type G[T1, T2 any] struct {
>>> X *T1
>>> Y *T2
>>> }
>>>
>>> type B = G[A1, A2]
>>>
>>>
>>> Here is the same program in the go playground: 
>>> https://go.dev/play/p/fjy9259UHPY.  If I click "Run" I get this output:
>>>
>>> # [play]
>>> vet: ./prog.go:15:4: invalid use of type alias B in recursive type (see 
>>> go.dev/issue/50729)
>>> Go vet failed.
>>> b = {X:0xc00009e050 Y:0xc00009e060}
>>> Program exited.
>>>
>>>
>>> So "go vet" fails, but the program builds and runs OK.  However, if I 
>>> run "go vet" on my machine, no errors are reported!
>>>
>>> Can someone explain what is happening? To sum up
>>> - the program builds and runs even though an error is reported in vscode 
>>> and the same error by go vet on the Go playground
>>> - go vet reports an error in the Go playground, but not on my machine 
>>> (they both reportedly run go 1.23.0)
>>> - possibly gopls reports this error too?  I do not know if it is the 
>>> tool that tells vscode of the error on my machine (I run gopls 0.16.1)
>>>
>>> What I'd like to know:
>>> - if someone can tell me how to determine what tool is telling vscode to 
>>> report this error, it would help me find where to report this issue
>>> - if someone could confirm whether the program is indeed supposed to be 
>>> correct, it would also help me (I suspect it should be correct, as it 
>>> builds and runs successfully)
>>>
>>> Thanks in advance
>>>
>>> -- 
>>> Arnaud
>>>
>>> PS: Apologies for the html-formatted email, but I couldn't figure out 
>>> how to paste code into gmail without losing all the indentation
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/3084309c-bac4-4851-ab1f-364568b4400cn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/3084309c-bac4-4851-ab1f-364568b4400cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ef0fd15b-27ed-433f-a519-122ff3e84974n%40googlegroups.com.

Reply via email to