This is a manual undo of CL
5674098.
It does not implement the even less strict spec
that we just agreed on, but it gets us back where
we were at the last weekly.
R=ken2
CC=golang-dev
https://golang.org/cl/
5683069
n->diag = 1;
}
return;
-
+
case TUP(OADD, CTINT):
case TUP(OADD, CTRUNE):
mpaddfixfix(v.u.xval, rv.u.xval, 0);
n->diag = 1;
}
return;
+
case TUP(OADD, CTCPLX):
mpaddfltflt(&v.u.cval->real, &rv.u.cval->real);
mpaddfltflt(&v.u.cval->imag, &rv.u.cval->imag);
n->type = idealstring;
break;
case CTBOOL:
- n->type = types[TBOOL];
+ n->type = idealbool;
break;
case CTINT:
case CTRUNE:
defaultlit(&n->left, t);
defaultlit(&n->right, t);
}
- if(n->type == types[TBOOL] || n->type == idealstring)
+ if(n->type == idealbool || n->type == idealstring)
n->type = types[n->type->etype];
else
n->type = n->left->type;
case OLITERAL:
t = n->type;
- if(t != types[n->type->etype] && t != idealstring) {
+ if(t != types[n->type->etype] && t != idealbool && t != idealstring) {
if(isptr[t->etype])
t = t->type;
if (t && t->sym && t->sym->def && t->sym->pkg != localpkg && t->sym->pkg != builtinpkg) {
}
if(t->etype < nelem(basicnames) && basicnames[t->etype] != nil) {
- if(fmtmode == FErr && t == idealstring)
+ if(fmtmode == FErr && (t == idealbool || t == idealstring))
fmtstrcpy(fp, "ideal ");
return fmtstrcpy(fp, basicnames[t->etype]);
}
return fmtprint(f, "%S", n->sym);
if(n->val.ctype == CTNIL)
n = n->orig; // if this node was a nil decorated with at type, print the original naked nil
- if(n->type != types[n->type->etype] && n->type != idealstring) {
+ if(n->type != types[n->type->etype] && n->type != idealbool && n->type != idealstring) {
// Need parens when type begins with what might
// be misinterpreted as a unary operator: * or <-.
if(isptr[n->type->etype] || (n->type->etype == TCHAN && n->type->chan == Crecv))
EXTERN Type* types[NTYPE];
EXTERN Type* idealstring;
+EXTERN Type* idealbool;
EXTERN Type* bytetype;
EXTERN Type* runetype;
EXTERN Type* errortype;
// this is the ideal form
// (the type of x in const x = "hello").
idealstring = typ(TSTRING);
+ idealbool = typ(TBOOL);
s = pkglookup("true", builtinpkg);
s->def = nodbool(1);
s->def->sym = lookup("true");
- s->def->type = types[TBOOL];
+ s->def->type = idealbool;
s = pkglookup("false", builtinpkg);
s->def = nodbool(0);
s->def->sym = lookup("false");
- s->def->type = types[TBOOL];
+ s->def->type = idealbool;
s = lookup("_");
s->block = -100;
c = nodintconst(0);
c->val.ctype = CTBOOL;
c->val.u.bval = b;
- c->type = types[TBOOL];
+ c->type = idealbool;
return c;
}
{
if(t == T)
return 0;
- if(t == idealstring)
+ if(t == idealstring || t == idealbool)
return 1;
switch(t->etype) {
case TNIL:
type B bool
b := B(false)
mb := make(map[B]int)
+ mb[false] = 42 // this should work: false is assignment compatible with B
mb[b] = 42
type Z int
func (Map) M() {}
+
// These functions check at run time that the default type
// (in the absence of any implicit conversion hints)
// is the given type.
func main() {
var (
a Array
- b Bool = Bool(true)
+ b Bool = true
c Chan = make(Chan)
f Float = 1
i Int = 1
isBool(b)
asBool(!b)
isBool(!b)
+ asBool(true)
asBool(*&b)
isBool(*&b)
asBool(Bool(true))
func main() {
var (
- b Bool = Bool(true)
+ b Bool = true
i, j int
c = make(chan int)
m = make(Map)
asBool(b)
asBool(!b)
- asBool(true) // ERROR "cannot use.*type bool.*as type Bool"
+ asBool(true)
asBool(*&b)
asBool(Bool(true))
asBool(1 != 2) // ERROR "cannot use.*type bool.*as type Bool"