]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: do not report error for invalid constant
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 4 Mar 2021 15:24:58 +0000 (22:24 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 5 Mar 2021 18:46:43 +0000 (18:46 +0000)
Invalid constant was already reported by noder, so don't re-check in
typecheck, which lead to compiler crashing.

Updates #43311

Change-Id: I48e2f540601cef725c1ff628c066ed15d848e771
Reviewed-on: https://go-review.googlesource.com/c/go/+/298713
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/typecheck/typecheck.go
test/char_lit1.go
test/fixedbugs/issue20232.go

index 8c456e4561e9b22d750232157398d67a0e1ad257..4c7c9fc322f97726ceabf3368dc2fd906a20e606 100644 (file)
@@ -689,7 +689,7 @@ func (p *noder) expr(expr syntax.Expr) ir.Node {
                if expr.Kind == syntax.RuneLit {
                        n.SetType(types.UntypedRune)
                }
-               n.SetDiag(expr.Bad) // avoid follow-on errors if there was a syntax error
+               n.SetDiag(expr.Bad || n.Val().Kind() == constant.Unknown) // avoid follow-on errors if there was a syntax error
                return n
        case *syntax.CompositeLit:
                n := ir.NewCompLitExpr(p.pos(expr), ir.OCOMPLIT, p.typeExpr(expr.Type), nil)
index 647465af4fe0f2c3bd0b35d00c3d3be3298b269e..548c1af85cd8c21f7e15b48089bc21cefea3b1a1 100644 (file)
@@ -482,7 +482,9 @@ func typecheck1(n ir.Node, top int) ir.Node {
 
        case ir.OLITERAL:
                if n.Sym() == nil && n.Type() == nil {
-                       base.Fatalf("literal missing type: %v", n)
+                       if !n.Diag() {
+                               base.Fatalf("literal missing type: %v", n)
+                       }
                }
                return n
 
index 489744b6e9888c733d05fa84baa34bbce2f48a1e..8899aff83aba34a42e887f0faa48e2630fbfd686 100644 (file)
@@ -1,4 +1,4 @@
-// errorcheck
+// errorcheck -d=panic
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index 7a0300a4c42d10f29c0a2ce1e4c2e4283efb499c..846843dccbae01d87a4ce54ea10a6a96078f0042 100644 (file)
@@ -1,4 +1,4 @@
-// errorcheck
+// errorcheck -d=panic
 
 // Copyright 2017 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style