mirror of
https://github.com/golang/go
synced 2024-11-21 22:34:48 -07:00
gc: fix typed constant declarations
Fixes #1411. R=rsc, gri, ejsherry CC=golang-dev https://golang.org/cl/4035042
This commit is contained in:
parent
25f762c75b
commit
661bcb773b
@ -269,9 +269,15 @@ walkdef(Node *n)
|
|||||||
}
|
}
|
||||||
t = n->type;
|
t = n->type;
|
||||||
if(t != T) {
|
if(t != T) {
|
||||||
convlit(&e, t);
|
if(!okforconst[t->etype]) {
|
||||||
if(!okforconst[t->etype])
|
|
||||||
yyerror("invalid constant type %T", t);
|
yyerror("invalid constant type %T", t);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if(!isideal(e->type) && !eqtype(t, e->type)) {
|
||||||
|
yyerror("cannot use %+N as type %T in const initializer", e, t);
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
convlit(&e, t);
|
||||||
}
|
}
|
||||||
n->val = e->val;
|
n->val = e->val;
|
||||||
n->type = e->type;
|
n->type = e->type;
|
||||||
|
12
test/fixedbugs/bug318.go
Normal file
12
test/fixedbugs/bug318.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// errchk $G $D/$F.go
|
||||||
|
|
||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Issue 1411.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
const ui uint = 0
|
||||||
|
const i int = ui // ERROR "type"
|
Loading…
Reference in New Issue
Block a user