From d64cb6a38315b993dfcc58ed1f2f11de17b5c472 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Thu, 19 May 2022 22:27:44 +0800 Subject: [PATCH] fix #1197 --- cl/compile_test.go | 13 +++++++++++++ cl/stmt.go | 3 +++ cmd/goptestgo/goptestgo.go | 1 + 3 files changed, 17 insertions(+) diff --git a/cl/compile_test.go b/cl/compile_test.go index 1bfa8fb01..08a367183 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -143,6 +143,19 @@ var x string = c.Str() `) } +func TestUnderscoreRedeclared_Issue1197(t *testing.T) { + gopClTest(t, ` +func() (_ [2]int) { type _ int; return }() +`, `package main + +func main() { + func() (_ [2]int) { + return + }() +} +`) +} + func TestInterfaceBugNilUnderlying_Issue1196(t *testing.T) { gopClTest(t, ` func main() { diff --git a/cl/stmt.go b/cl/stmt.go index f83a339ed..5f37927de 100644 --- a/cl/stmt.go +++ b/cl/stmt.go @@ -728,6 +728,9 @@ func compileDeclStmt(ctx *blockCtx, expr *ast.DeclStmt) { func compileType(ctx *blockCtx, t *ast.TypeSpec) { name := t.Name.Name + if name == "_" { + return + } if t.Assign != token.NoPos { // alias type ctx.cb.AliasType(name, toType(ctx, t.Type)) } else { diff --git a/cmd/goptestgo/goptestgo.go b/cmd/goptestgo/goptestgo.go index c570ced1d..3520ee723 100644 --- a/cmd/goptestgo/goptestgo.go +++ b/cmd/goptestgo/goptestgo.go @@ -82,6 +82,7 @@ var ( "issue18149.go": {}, "issue22662.go": {}, "issue27201.go": {}, + "issue46903.go": {}, "nilptr_aix.go": {}, "inline_literal.go": {}, "returntype.go": {}, // not a problem