Commit 14be733a authored by Russ Cox's avatar Russ Cox

bug197

R=ken
OCL=33765
CL=33765
parent 9feee91d
...@@ -77,6 +77,8 @@ convlit1(Node **np, Type *t, int explicit) ...@@ -77,6 +77,8 @@ convlit1(Node **np, Type *t, int explicit)
return; return;
if(eqtype(t, n->type)) if(eqtype(t, n->type))
return; return;
if(!explicit && n->type->etype != TIDEAL && n->type != idealstring && n->type->etype != TNIL)
return;
//dump("convlit1", n); //dump("convlit1", n);
if(n->op == OLITERAL) { if(n->op == OLITERAL) {
......
...@@ -330,7 +330,7 @@ enum ...@@ -330,7 +330,7 @@ enum
OCMPIFACE, OCMPSTR, OCMPIFACE, OCMPSTR,
OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT, OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
OCOMPSLICE, OCOMPMAP, OCOMPSLICE, OCOMPMAP,
OCONV, OCONVNOP, OCONVA2S, OCONVIFACE, OCONVSLICE, OCONV, OCONVNOP, OCONVIFACE, OCONVSLICE,
ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE, ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT, ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
ODOTTYPE, ODOTTYPE,
......
...@@ -258,6 +258,9 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -258,6 +258,9 @@ exprfmt(Fmt *f, Node *n, int prec)
break; break;
case OCONV: case OCONV:
case OCONVNOP:
case OCONVSLICE:
case OCONVIFACE:
fmtprint(f, "%T(", n->type); fmtprint(f, "%T(", n->type);
exprfmt(f, n->left, 0); exprfmt(f, n->left, 0);
fmtprint(f, ")"); fmtprint(f, ")");
......
...@@ -87,6 +87,8 @@ reswitch: ...@@ -87,6 +87,8 @@ reswitch:
ok |= Erv; ok |= Erv;
if(n->iota && !(top & Eiota)) if(n->iota && !(top & Eiota))
yyerror("use of iota not in constant initializer"); yyerror("use of iota not in constant initializer");
if(n->val.ctype == CTSTR)
n->type = idealstring;
goto ret; goto ret;
case ONONAME: case ONONAME:
...@@ -1268,7 +1270,9 @@ typecheckconv(Node *nconv, Node *n, Type *t, int explicit) ...@@ -1268,7 +1270,9 @@ typecheckconv(Node *nconv, Node *n, Type *t, int explicit)
if(n->type == T) if(n->type == T)
return n; return n;
if(cvttype(t, n->type) && n->op == OLITERAL) { if(n->op == OLITERAL)
if(explicit || n->type->etype == TIDEAL || n->type == idealstring || n->type->etype == TNIL)
if(cvttype(t, n->type)) {
// can convert literal in place // can convert literal in place
// TODO(rsc) is this needed? // TODO(rsc) is this needed?
n1 = nod(OXXX, N, N); n1 = nod(OXXX, N, N);
...@@ -1286,6 +1290,10 @@ typecheckconv(Node *nconv, Node *n, Type *t, int explicit) ...@@ -1286,6 +1290,10 @@ typecheckconv(Node *nconv, Node *n, Type *t, int explicit)
return n; return n;
case 0: case 0:
if(nconv) {
nconv->op = OCONVNOP;
return nconv;
}
return n; return n;
} }
......
// errchk $G $D/$F.go
// Copyright 2009 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.
package main
type T int
type U int
var x int
var t T = int(0) // ERROR "cannot use"
var t1 T = int(x) // ERROR "cannot use"
var u U = int(0) // ERROR "cannot use"
var u1 U = int(x) // ERROR "cannot use"
type S string
var s S
var s1 = s + "hello"
var s2 = "hello" + s
var s3 = s + string("hello") // ERROR "invalid operation"
var s4 = string("hello") + s // ERROR "invalid operation"
var r string
var r1 = r + "hello"
var r2 = "hello" + r
var r3 = r + string("hello")
var r4 = string("hello") + r
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment