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

go/types: discrepancy in type checking compared to types2 #67436

Closed
griesemer opened this issue May 16, 2024 · 2 comments
Closed

go/types: discrepancy in type checking compared to types2 #67436

griesemer opened this issue May 16, 2024 · 2 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

For

// -gotypesalias=1

package p

var x T[B]

type T[_ any] struct{}
type A T[B]
type B = T[A]

types2 produces the trace:

testdata/manual.go:7:6: -- checking type T (white, objPath = )
testdata/manual.go:7:10:        .  -- type any
testdata/manual.go:7:10:        .  => any (under = any) // *Alias
testdata/manual.go:7:15:        .  -- type struct{}
testdata/manual.go:7:15:        .  => struct{} // *Struct
testdata/manual.go:7:6: => type T[_ any] struct{} (black)

testdata/manual.go:8:6: -- checking type A (white, objPath = )
testdata/manual.go:8:9: .  -- type T[B]
testdata/manual.go:8:8: .  .  -- instantiating type T with [B]
testdata/manual.go:8:8: .  .  .  -- type T
testdata/manual.go:8:8: .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:8:10:        .  .  .  -- type B
testdata/manual.go:9:6: .  .  .  .  -- checking type B (white, objPath = A)
testdata/manual.go:9:11:        .  .  .  .  .  -- type T[A]
testdata/manual.go:9:10:        .  .  .  .  .  .  -- instantiating type T with [A]
testdata/manual.go:9:10:        .  .  .  .  .  .  .  -- type T
testdata/manual.go:9:10:        .  .  .  .  .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:9:12:        .  .  .  .  .  .  .  -- type A
testdata/manual.go:8:6: .  .  .  .  .  .  .  .  ## cycle detected: objPath = A->B->A (len = 2)
testdata/manual.go:8:6: .  .  .  .  .  .  .  .  ## cycle contains: 0 values, 1 type definitions
testdata/manual.go:8:6: .  .  .  .  .  .  .  .  => cycle is valid
testdata/manual.go:9:12:        .  .  .  .  .  .  .  => A (under = <nil>) // *Named
testdata/manual.go:9:10:        .  .  .  .  .  .  => T[A]
testdata/manual.go:9:11:        .  .  .  .  .  => T[A] (under = <nil>) // *Named
testdata/manual.go:9:6: .  .  .  .  => type B = T[A] (black)
testdata/manual.go:8:10:        .  .  .  => B (under = <nil>) // *Alias
testdata/manual.go:8:8: .  .  => T[B]
testdata/manual.go:8:9: .  => T[B] (under = <nil>) // *Named
testdata/manual.go:8:8: -- Named.expandUnderlying T[B]
testdata/manual.go:8:8: => T[B] (tparams = [], under = <nil>)
testdata/manual.go:8:6: => type A struct{} (black)

testdata/manual.go:5:5: -- checking var x (white, objPath = )
testdata/manual.go:5:8: .  -- type T[B]
testdata/manual.go:5:7: .  .  -- instantiating type T with [B]
testdata/manual.go:5:7: .  .  .  -- type T
testdata/manual.go:5:7: .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:5:9: .  .  .  -- type B
testdata/manual.go:5:9: .  .  .  => B (under = <nil>) // *Alias
testdata/manual.go:5:7: .  .  => T[B]
testdata/manual.go:5:8: .  => T[B] (under = struct{}) // *Named
testdata/manual.go:5:5: => var x T[B] (black)

but go/types produces:

testdata/manual.go:5:5: -- checking var x (white, objPath = )
testdata/manual.go:5:7: .  -- type T[B]
testdata/manual.go:5:7: .  .  -- instantiating type T with [B]
testdata/manual.go:5:7: .  .  .  -- type T
testdata/manual.go:7:6: .  .  .  .  -- checking -> type T (white, objPath = x)
testdata/manual.go:7:8: .  .  .  .  .  type params = [_₁]
testdata/manual.go:7:10:        .  .  .  .  .  -- type any
testdata/manual.go:7:10:        .  .  .  .  .  => any (under = any) // *Alias
testdata/manual.go:7:15:        .  .  .  .  .  -- type struct{}
testdata/manual.go:7:15:        .  .  .  .  .  => struct{} // *Struct
testdata/manual.go:7:6: .  .  .  .  => -> type T[_ any] struct{} (black)
testdata/manual.go:5:7: .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:5:9: .  .  .  -- type B
testdata/manual.go:9:6: .  .  .  .  -- checking -> type B (white, objPath = x)
testdata/manual.go:9:10:        .  .  .  .  .  -- type T[A]
testdata/manual.go:9:10:        .  .  .  .  .  .  -- instantiating type T with [A]
testdata/manual.go:9:10:        .  .  .  .  .  .  .  -- type T
testdata/manual.go:9:10:        .  .  .  .  .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:9:12:        .  .  .  .  .  .  .  -- type A
testdata/manual.go:8:6: .  .  .  .  .  .  .  .  -- checking -> type A (white, objPath = x->B)
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  -- type T[B]
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  .  -- instantiating type T with [B]
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  .  .  -- type T
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  .  .  => T[_₁ any] (under = struct{}) // *Named
testdata/manual.go:8:10:        .  .  .  .  .  .  .  .  .  .  .  -- type B
testdata/manual.go:9:6: .  .  .  .  .  .  .  .  .  .  .  .  ## cycle detected: objPath = B->A->B (len = 2)
testdata/manual.go:9:6: .  .  .  .  .  .  .  .  .  .  .  .  ## cycle contains: 0 values, 1 type definitions
testdata/manual.go:9:6: .  .  .  .  .  .  .  .  .  .  .  .  => cycle is valid
testdata/manual.go:8:10:        .  .  .  .  .  .  .  .  .  .  .  => B (under = invalid type) // *Alias
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  .  => invalid type
testdata/manual.go:8:8: .  .  .  .  .  .  .  .  .  => invalid type // *Basic
testdata/manual.go:8:6: .  .  .  .  .  .  .  .  => -> type A invalid type (black)
testdata/manual.go:9:12:        .  .  .  .  .  .  .  => A (under = invalid type) // *Named
testdata/manual.go:9:10:        .  .  .  .  .  .  => T[A]
testdata/manual.go:9:10:        .  .  .  .  .  => T[A] (under = <nil>) // *Named
testdata/manual.go:9:6: .  .  .  .  => -> type B = T[A] (black)
testdata/manual.go:5:9: .  .  .  => B (under = <nil>) // *Alias
testdata/manual.go:5:7: .  .  => T[B]
testdata/manual.go:5:7: .  => T[B] (under = <nil>) // *Named
testdata/manual.go:5:5: => var x T[B] (black)

Note the invalid underlying types for A and the different evaluation strategy.

This causes at least one of the failures in #66859.

@griesemer griesemer added this to the Go1.23 milestone May 16, 2024
@griesemer griesemer self-assigned this May 16, 2024
@griesemer
Copy link
Contributor Author

griesemer commented May 16, 2024

Looks like this was already fixed in types2 with CL 577616 but not ported.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/586236 mentions this issue: go/types: re-enable suppressed gcimporter tests

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants