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

x/tools/gopls: panic exporting invalid constant declaration #60605

Closed
youryharchenko opened this issue Jun 3, 2023 · 6 comments
Closed

x/tools/gopls: panic exporting invalid constant declaration #60605

youryharchenko opened this issue Jun 3, 2023 · 6 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@youryharchenko
Copy link

gopls version: v0.12.2 (go1.19.6)
gopls flags:
update flags: proxy
extension version: 0.38.0
go version: 1.19.6
environment: Visual Studio Code linux
initialization error: undefined
issue timestamp: Sat, 03 Jun 2023 11:15:12 GMT
restart history:
Sat, 03 Jun 2023 11:10:13 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

const EPSILON float64 = 1e-

panic: internal error: assertion failed

goroutine 842 [running]:
golang.org/x/tools/internal/gcimporter.iexportCommon.func1()
	  iexport.go:93  0x8a
panic({0xd7df60, 0x115b670})
	  panic.go:884  0x212
golang.org/x/tools/internal/gcimporter.assert(...)
	  iexport.go:1141
golang.org/x/tools/internal/gcimporter.constantToFloat({0x1165398%3F, 0x1713530%3F})
	  iexport.go:967  0x147
golang.org/x/tools/internal/gcimporter.(*exportWriter).value(0xc00141c9c0, {0x1161098%3F, 0x16c0000}, {0x1165398, 0x1713530})
	  iexport.go:930  0x31e
golang.org/x/tools/internal/gcimporter.(*iexporter).doDecl(0xc000ea20f0, {0x116d6b8%3F, 0xc001698cc0%3F})
	  iexport.go:481  0x32d
golang.org/x/tools/internal/gcimporter.iexportCommon({0x115d0a0, 0xc001824870}, 0xc000b5a080, 0x0, 0x1, 0x2, {0xc0011e1c90, 0x1, 0x0%3F})
	  iexport.go:139  0x35c
golang.org/x/tools/internal/gcimporter.IExportShallow(0xdc06a0%3F, 0xc000247810)
	  iexport.go:43  0x75
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).checkPackage.func1()
	  check.go:646  0x2b1
created by golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).checkPackage
	  check.go:638  0x305
[Error - 2:14:43 PM] 

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

findleyr commented Jun 5, 2023

Thanks very much for the report, and for noticing the repro conditions.

This is surely a bug in the exporter, which we will fix.

Transferring to the Go issue tracker.

@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: panic exporting invalid constant declaration Jun 5, 2023
@findleyr
Copy link
Contributor

findleyr commented Jun 5, 2023

CC @adonovan @griesemer

@findleyr findleyr transferred this issue from golang/vscode-go Jun 5, 2023
@findleyr findleyr added this to the gopls/v0.12.2 milestone Jun 5, 2023
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jun 5, 2023
@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 5, 2023
@griesemer
Copy link
Contributor

This is the assertion that fails (iexport.go:967):

// Value too large to represent as a fraction => inaccessible.
// TODO(gri): add big.Float accessor to constant.Value.
_, ok := f.SetString(x.ExactString())
assert(ok)

ExactString must be returning a string that cannot be parsed successfully by SetString.

The following code

package p
const _ float64 = 1e-

crashes gopls for me (see also #60649). The 1e- leads to an unknown constant, the ExactString of which is "unknown". This cannot be handled by SetString.

@griesemer
Copy link
Contributor

The exportWriter.value method should probably check if the constant value v is known in the first place. If it is not, it should treat it like having invalid type.

@findleyr
Copy link
Contributor

findleyr commented Jun 7, 2023

Thanks for investigating! I'll fix the x/tools exporter.

@findleyr findleyr self-assigned this Jun 7, 2023
@gopherbot
Copy link

Change https://go.dev/cl/501209 mentions this issue: internal/gcimporter: treat unknown constant values the same as invalid

@griesemer griesemer 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 Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants