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

cmd/compile: error message dumps internal details #46558

ianlancetaylor opened this issue Jun 3, 2021 · 4 comments

cmd/compile: error message dumps internal details #46558

ianlancetaylor opened this issue Jun 3, 2021 · 4 comments


Copy link

@ianlancetaylor ianlancetaylor commented Jun 3, 2021

Using a compiler built at 6d98301, compiling this erroneous file gives a strange error message that seems to dump an internal compiler data structure.

package p

func F(s string) {
	switch s[0] {
	case 'a':
		case s[2] {
		case 'b':
> go build foo.go
# command-line-arguments
NOT NTYPE [0xc00034e0c0]
.   INDEX # foo.go:6
.   .   NAME-p.s Class:PPARAM Offset:0 OnStack # foo.go:3
.   .   NAME-ntype
.   .   .   NONAME-p.string # foo.go:3
.   .   LITERAL-2 untyped int # foo.go:6
../foo.go:7:3: syntax error: unexpected case, expecting expression
../foo.go:8:4: syntax error: unexpected newline, expecting :

This does not happen with Go 1.16.

CC @mdempsky

@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jun 3, 2021
Copy link

@mdempsky mdempsky commented Jun 3, 2021

I think there are two minor issues here:

  1. cmd/compile/internal/parser is now trying to parse s[2] { case 'b': } as a composite literal of instantiated type s[2]. This then fails during noding, because s[2] isn't a valid syntactic form for a type expression (prior to generics, which noder doesn't support). (I'm inferring this because of the change in error message/lines from 1.16 to master.)
  2. cmd/compile/internal/noder has an ir.Dump call that Russ added for debugging some ir.Node refactoring stuff. It will never print on valid input, and (I think) it also never printed before the change in parser semantics.

Maybe a parser change is appropriate here (/cc @griesemer). But I also think it's fine that we just remove the spurious ir.Dump. It's not serving any purpose now that things have stabilized.

@griesemer griesemer self-assigned this Jun 3, 2021
Copy link

@griesemer griesemer commented Jun 3, 2021

Yeah, the parser should probably handle this case as it gets badly into the weeds otherwise. Will fix.

@griesemer griesemer modified the milestones: Backlog, Go1.18 Jun 3, 2021
Copy link

@gopherbot gopherbot commented Jun 4, 2021

Change mentions this issue: cmd/compile: remove spurious ir.Dump

gopherbot pushed a commit that referenced this issue Jun 4, 2021
This ir.Dump call is a debugging artifact introduced in, which should never be printed for valid,
non-generic code, but evidently can now sometimes appear due to how
the parser handles invalid syntax.

The parser should probably not recognize "x[2]" as a type expression
in non-generics mode, but also probably we shouldn't try noding after
reporting syntax errors. Either way, this diagnostic has outlived its
usefulness, and noder's days are numbered anyway, so we might as well
just remove it to save end users any confusion.

Updates #46558.

Change-Id: Ib68502ef834d610b883c2f2bb11d9b385bc66e37
Trust: Matthew Dempsky <>
Run-TryBot: Matthew Dempsky <>
Reviewed-by: Robert Griesemer <>
TryBot-Result: Go Bot <>
Copy link

@gopherbot gopherbot commented Jun 4, 2021

Change mentions this issue: [dev.typeparams] cmd/compile/internal/syntax: not all index expressions can be instantiated types

gopherbot pushed a commit that referenced this issue Jun 5, 2021
…ns can be instantiated types

An index expression followed by an opening "{" may indicate
a composite literal but only if the index expression can be
a type. Exclude cases where the index expression cannot be
a type (e.g. s[0], a[i+j], etc.).

This leads to a better error message in code that is erroneous.

Fixes #46558.

Change-Id: Ida9291ca30683c211812dfb95abe4969f44c474f
Trust: Robert Griesemer <>
Reviewed-by: Robert Findley <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants