Skip to content

Commit 9e6b1fc

Browse files
committed
cmd/compile: do not report error for invalid constant
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 <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 51d8d35 commit 9e6b1fc

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/cmd/compile/internal/noder/noder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func (p *noder) expr(expr syntax.Expr) ir.Node {
689689
if expr.Kind == syntax.RuneLit {
690690
n.SetType(types.UntypedRune)
691691
}
692-
n.SetDiag(expr.Bad) // avoid follow-on errors if there was a syntax error
692+
n.SetDiag(expr.Bad || n.Val().Kind() == constant.Unknown) // avoid follow-on errors if there was a syntax error
693693
return n
694694
case *syntax.CompositeLit:
695695
n := ir.NewCompLitExpr(p.pos(expr), ir.OCOMPLIT, p.typeExpr(expr.Type), nil)

src/cmd/compile/internal/typecheck/typecheck.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ func typecheck1(n ir.Node, top int) ir.Node {
482482

483483
case ir.OLITERAL:
484484
if n.Sym() == nil && n.Type() == nil {
485-
base.Fatalf("literal missing type: %v", n)
485+
if !n.Diag() {
486+
base.Fatalf("literal missing type: %v", n)
487+
}
486488
}
487489
return n
488490

test/char_lit1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// errorcheck
1+
// errorcheck -d=panic
22

33
// Copyright 2009 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style

test/fixedbugs/issue20232.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// errorcheck
1+
// errorcheck -d=panic
22

33
// Copyright 2017 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style

0 commit comments

Comments
 (0)