You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package bbb
type Info struct {
Abc int
Efg int
Inner InnerInfo
}
type InnerInfo struct {
Innera int
Innerb int
}
func (info *Info) String() string {
// b, _ := json.MarshalIndent(info, "", " ")
//return string(b)
return ""
}
func Add(a IntAlias, b IntAlias, info *Info) {
println("this is pa aaa Add() a = ", a, " b = ", b, " info = ", info.String())
}
func Sub(a int , b int, info *Info) {
println("this is pa aaa Sub() a = ", a, " b = ", b, " info = ", info.String())
}
func Mul(a int, info Info) {
println("this is pa aaa Mul(), a = ", a, " info = ", info.String())
}
pa/bbb/inner_linux_zos.go
//go:build zos
// Tags altered by Wharf (added zos)
//
package bbb
// import "encoding/json"
type Info struct {
Abc int
Efg int
Inner InnerInfo
}
type InnerInfo struct {
Innera int
Innerb int
}
func (info *Info) String() string {
return ""
}
func Add(a IntAlias, b IntAlias, info *Info) {
println("this is pa aaa Add() a = ", a, " b = ", b, " info = ", info.String())
}
func Sub(a int, b int, info *Info) {
println("this is pa aaa Sub() a = ", a, " b = ", b, " info = ", info.String())
}
func Mul(a int, info Info) {
println("this is pa aaa Mul(), a = ", a, " info = ", info.String())
}
pa/aaa/outter.go
//go:build zos
package bbb
type Info struct {
Abc int
Efg int
Inner InnerInfo
}
type InnerInfo struct {
Innera int
Innerb int
}
func (info *Info) String() string {
return ""
}
//func Add(a IntAlias, b IntAlias, info *Info) {
// println("this is pa aaa Add() a = ", a, " b = ", b, " info = ", info.String())
// }
func Sub(a int, b int, info *Info) {
println("this is pa aaa Sub() a = ", a, " b = ", b, " info = ", info.String())
}
func Mul(a int, info Info) {
println("this is pa aaa Mul(), a = ", a, " info = ", info.String())
}
pb/inner/inner.go
package inner
import "pa/aaa"
import "pa/bbb"
func CallToAdd(a int, b int, info *bbb.Info) {
println("pb inner CallToAdd()")
aaa.Add(a, b, info)
}
func CallToSub(a int, b int, info *bbb.Info) {
println("pb inner CallToSub")
aaa.Sub(a, b, info)
}
func CallToMul(a int, info bbb.Info) {
println("pb inner CallToMul()")
aaa.Mul(a, info)
}
load err = <nil> pkgs = [pa/aaa pa/bbb pb/inner]
pkgs[0] = pkgs[0].Types = package ("pa/aaa") type name = 0x5f5a80
parseFile err = <nil> fset = &{{{0 0} 0 0 {{} 0} {{} 0}} 474 [0xc00007e240] {[] {} 0xc00007e240}}
parseFile err = <nil> fset = &{{{0 0} 0 0 {{} 0} {{} 0}} 1068 [0xc00007e240 0xc00007e420] {[] {} 0xc00007e420}}
bbb/constant.go parseFile err = <nil> fset = &{{{0 0} 0 0 {{} 0} {{} 0}} 1791 [0xc00007e240 0xc00007e420 0xc00007e600 0xc00007e7e0] {[] {} 0xc00007e7e0}}
parseFile err = <nil> fset = &{{{0 0} 0 0 {{} 0} {{} 0}} 1791 [0xc00007e240 0xc00007e420 0xc00007e600 0xc00007e7e0] {[] {} 0xc00007e7e0}}
parseFile err = <nil> fset = &{{{0 0} 0 0 {{} 0} {{} 0}} 1791 [0xc00007e240 0xc00007e420 0xc00007e600 0xc00007e7e0] {[] {} 0xc00007e7e0}}
mainAST = &{<nil> 350 main [0xc0000a7d00 0xc0000a7d40 0xc00009d800] 350 776 scope 0xc000014c50 {
func main
}
[0xc00009d560 0xc00009d590] [println bbb bbb bbb bbb inner inner inner println] [] }
typecheck err = /home/zhilong/goExperiment/testAST/pa/aaa/outter.go:3:8: could not import pa/bbb (invalid package name: "")
find id = pa/aaa setting type: package aaa ("pa/aaa")
find id = pa/bbb setting type: package bbb ("pa/bbb")
after set type
finish pkg = package aaa ("pa/aaa") err = <nil>
typecheck err = /home/zhilong/goExperiment/testAST/pb/inner/inner.go:8:16: cannot use info (variable of type *bbb.Info) as *invalid type value in argument to aaa.Add
find id = pb/inner setting type: package inner ("pb/inner")
after set pb/inner err = /home/zhilong/goExperiment/testAST/pb/inner/inner.go:8:16: cannot use info (variable of type *bbb.Info) as *invalid type value in argument to aaa.Add
finish setup pb <nil>
find id = pa/bbb setting type: package bbb ("pa/bbb")
check main again
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:26:24: cannot use info1 (variable of type *bbb.Info) as *bbb.Info value in argument to inner.CallToAdd
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:27:24: cannot use info1 (variable of type *bbb.Info) as *bbb.Info value in argument to inner.CallToSub
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:28:21: cannot use info2 (variable of type bbb.Info) as bbb.Info value in argument to inner.CallToMul
What did you expect to see?
The very last few lines of the output
check main again
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:26:24: cannot use info1 (variable of type *bbb.Info) as *bbb.Info value in argument to inner.CallToAdd
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:27:24: cannot use info1 (variable of type *bbb.Info) as *bbb.Info value in argument to inner.CallToSub
typecheck err = /home/zhilong/goExperiment/testAST/pb/main.go:28:21: cannot use info2 (variable of type bbb.Info) as bbb.Info value in argument to inner.CallToMul
The variable type is the same but the compiler is complaining that they are different.
There should be no error at the last step of the Check function
The text was updated successfully, but these errors were encountered:
The issue arises within the type checking process, specifically in the func AssignableTo(V, T Type) bool function, which fails to provide accurate type checks for Named type. .
The function relies on indenticalOrigin to verify the original type. However, the problem lies in its use of the == operator to compare Name structs that include pointers. This comparison method can lead to inaccurate results as it checks memory addresses rather than the actual content of the structs.
Compounding this issue is Wharf's behavior of creating a new package instance each time it filters a configuration. Consequently, pointers within Name structs may differ between package instances.
This is WAI. Each call to conf.Check returns a new *types.Package and each *type.Named within that copy of the package is considered distinct. (As for why? A lot gets pinned to memory in the implementation or speed and simplicity, and there are issues of temporal consistency.) The expectation is that if a user of go/types retype checks package, e.g. "pa/bbb", they also retype all packages that transitively import that package, e.g. "pa/main" and "pb/inner". This is what gopls does.
The documentation could be improved #53914. There is also a proposal to change this behavior #57497.
Go version
go1.21 linux/arm64
Output of
go env
in your module/workspace:What did you do?
I have the following project
pa/bbb/constant.go
pa/bbb/inner_linux.go
pa/bbb/inner_linux_zos.go
pa/aaa/outter.go
pb/inner/inner.go
pa/main.go
testType/main.go
What did you see happen?
Output:
What did you expect to see?
The very last few lines of the output
The variable type is the same but the compiler is complaining that they are different.
There should be no error at the last step of the Check function
The text was updated successfully, but these errors were encountered: