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, types2: gopls crash in recordTypeAndValue #51658

Closed
sxwebdev opened this issue Mar 12, 2022 · 12 comments
Closed

go/types, types2: gopls crash in recordTypeAndValue #51658

sxwebdev opened this issue Mar 12, 2022 · 12 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@sxwebdev
Copy link

gopls version: v0.8.0 (devel go1.19-c9b60632eb Fri Mar 4 14:10:38 2022 0000)
gopls flags:
update flags: proxy
extension version: 0.32.0
go version: devel 1.19-c9b60632eb
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Sat, 12 Mar 2022 09:33:04 GMT
restart history:
Sat, 12 Mar 2022 09:24:24 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: assertion failed

goroutine 1358 [running]:
go/types.(*Checker).handleBailout(0xc0022c28c0, 0xc002aed650)
	  check.go:303  0x8b
panic({0x1873ce0, 0x1bf6cf0})
	  panic.go:838  0x207
go/types.assert(...)
	  errors.go:21
go/types.(*Checker).recordTypeAndValue(0xc0022c28c0%3F, {0x1bfe410%3F, 0xc00102af60%3F}, 0x4%3F, {0x1bfc4f0%3F, 0xc002ab6fc0%3F}, {0x1c001e0%3F, 0x209df00%3F})
	  check.go:454  0x1f6
go/types.(*Checker).updateExprType0(0xc0022c28c0, {0xc002af0940%3F, 0x1bfc4f0%3F}, {0x1bfe410%3F, 0xc00102af60}, {0x1bfc4f0%3F, 0xc002ab6fc0%3F}, 0x0)
	  expr.go:593  0x831
go/types.(*Checker).updateExprType(...)
	  expr.go:476
go/types.(*Checker).convertUntyped(0xc0022c28c0, 0xc002af0940, {0x1bfc4f0, 0xc002ab6fc0})
	  expr.go:622  0x2b3
go/types.(*Checker).binary(0xa%3F, 0xc002af0900, {0x1bfe440%3F, 0xc0012868a0}, {0x1bfe7d0%3F, 0xc00102af00}, {0x1bfe410%3F, 0xc00102af60}, 0x27, 0xfd)
	  expr.go:1106  0x1f9
go/types.(*Checker).exprInternal(0xc0022c28c0, 0xc002af0900, {0x1bfe440%3F, 0xc0012868a0}, {0x0%3F, 0x0%3F})
	  expr.go:1624  0xa3f
go/types.(*Checker).rawExpr(0xc000600000%3F, 0xc002af0900%3F, {0x1bfe440%3F, 0xc0012868a0%3F}, {0x0%3F, 0x0%3F}, 0x0)
	  expr.go:1208  0x45
go/types.(*Checker).expr(0xc0022c28c0%3F, 0x0%3F, {0x1bfe440%3F, 0xc0012868a0%3F})
	  expr.go:1704  0x35
go/types.(*Checker).stmt(0xc0022c28c0, 0x0, {0x1bfe800%3F, 0xc0009c7600%3F})
	  stmt.go:567  0x2630
go/types.(*Checker).stmtList(0xc0022c28c0%3F, 0x0, {0xc00102b040%3F, 0x0%3F, 0xc002ab04c8%3F})
	  stmt.go:125  0xc9
go/types.(*Checker).funcBody(0xc0022c28c0, 0xc001ea52c0, {0x0%3F, 0xc002aed5f0%3F}, 0xc002af0480, 0xc001286900, {0x0, 0x0})
	  stmt.go:46  0x285
go/types.(*Checker).funcDecl.func1()
	  decl.go:788  0x45
go/types.(*Checker).processDelayed(0xc0022c28c0, 0x0)
	  check.go:388  0x39
go/types.(*Checker).checkFiles(0xc0022c28c0, {0xc002aa65c0%3F, 0xc002a93d60%3F, 0x0%3F})
	  check.go:336  0xcb
go/types.(*Checker).Files(...)
	  check.go:308
golang.org/x/tools/internal/lsp/cache.doTypeCheck({0x1bffbf8, 0xc002a89f40}, 0xc002478000, 0xc000a46f00, 0x2, 0xc002ab69f0, 0x1bfef80%3F)
	  check.go:551  0x97b
golang.org/x/tools/internal/lsp/cache.typeCheck({0x1bffbf8, 0xc002a89f40}, 0xc002478000, 0xc000a46f00, 0x2, 0xc002ab69f0%3F)
	  check.go:317  0xe5
golang.org/x/tools/internal/lsp/cache.(*snapshot).buildPackageHandle.func1({0x1bffbf8%3F, 0xc002a89f40}, {0x1bf9340%3F, 0xc002478000})
	  check.go:125  0x233
golang.org/x/tools/internal/memoize.(*Handle).run.func1()
	  memoize.go:327  0xa9
created by golang.org/x/tools/internal/memoize.(*Handle).run
	  memoize.go:320  0x1b8
[Error - 12:32:54] 

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

<OPTIONAL: ATTACH LOGS HERE>

@findleyr
Copy link
Contributor

Hi, this looks like it could be a type checker bug.

Do you recall the code you were working on when this crash occurred?

@findleyr
Copy link
Contributor

Transferring to the go issue tracker.

@findleyr findleyr changed the title gopls: automated issue report (crash) go/types, types2: gopls crash in recordTypeAndValue Mar 14, 2022
@findleyr findleyr transferred this issue from golang/vscode-go Mar 14, 2022
@findleyr
Copy link
Contributor

CC @griesemer

@findleyr findleyr added this to the Go1.19 milestone Mar 14, 2022
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 14, 2022
@sxwebdev
Copy link
Author

sxwebdev commented Mar 14, 2022

Hi, this looks like it could be a type checker bug.

Do you recall the code you were working on when this crash occurred?

Yes. You can remove the word interface next to the FloatType

package utils

type FloatType interface {
	float32 | float64
}

type IntegerType interface {
	int8 | int16 | int32 | int64 | int |
		uint8 | uint16 | uint32 | uint64 | uint
}

type ComplexType interface {
	complex64 | complex128
}

type Number interface {
	FloatType | IntegerType | ComplexType
}

image

@findleyr
Copy link
Contributor

Thanks for your reply. I'm not able to naively reproduce this. Can you share code that is using FloatType? The error may be occurring at the site of usage.

I'll try to look into the panicking stack to see if I can reconstruct.

@sxwebdev
Copy link
Author

I don't use the FloatType directly. But I have a function that uses the type Number

package utils

func GetDefaultNumber[T Number](value, defaultValue T) T {
	if value == 0 {
		return defaultValue
	}
	return value
}

@findleyr
Copy link
Contributor

Thanks, with that function I am able to reproduce!

@sxwebdev
Copy link
Author

Excellent!)

@findleyr findleyr added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 14, 2022
@griesemer
Copy link
Contributor

griesemer commented Mar 14, 2022

Minimized reproducer (for types2):

package p

type FloatType {
	float64
}

func _[T FloatType | int](x T) {
	_ = x == 0 
}

@griesemer griesemer self-assigned this Mar 14, 2022
@gopherbot
Copy link

Change https://go.dev/cl/392575 mentions this issue: go/types, types2: use correct underlying type in union set computation

@findleyr
Copy link
Contributor

@gopherbot please backport this to 1.18, it's a deterministic panic.

@gopherbot
Copy link

Backport issue(s) opened: #51665 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants