]> Cypherpunks repositories - gostls13.git/commitdiff
gc: return of ideal bool
authorRuss Cox <rsc@golang.org>
Wed, 22 Feb 2012 03:54:07 +0000 (22:54 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 22 Feb 2012 03:54:07 +0000 (22:54 -0500)
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

src/cmd/gc/const.c
src/cmd/gc/export.c
src/cmd/gc/fmt.c
src/cmd/gc/go.h
src/cmd/gc/lex.c
src/cmd/gc/subr.c
test/fixedbugs/bug285.go
test/named.go
test/named1.go

index abdd424394cc95b8c476aaa7f8278ef3288c0bd7..15c760b3a6c2d589e74465653db35b35d42f344d 100644 (file)
@@ -586,7 +586,7 @@ evconst(Node *n)
                        n->diag = 1;
                }
                return;
-       
+
        case TUP(OADD, CTINT):
        case TUP(OADD, CTRUNE):
                mpaddfixfix(v.u.xval, rv.u.xval, 0);
@@ -668,6 +668,7 @@ evconst(Node *n)
                        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);
@@ -943,7 +944,7 @@ nodlit(Val v)
                n->type = idealstring;
                break;
        case CTBOOL:
-               n->type = types[TBOOL];
+               n->type = idealbool;
                break;
        case CTINT:
        case CTRUNE:
@@ -1032,7 +1033,7 @@ defaultlit(Node **np, Type *t)
                        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;
index 1eb4c2280cf1bfb0aa530ccd6ad67cd66c89036c..bbed8ae36e18e168ae10712770029e01ebd746e2 100644 (file)
@@ -122,7 +122,7 @@ reexportdep(Node *n)
 
        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) {
index b942ed6082f42e306ff7c8f8d925cc17152b511c..093b276f070274747364fab722d95caac725fdee 100644 (file)
@@ -602,7 +602,7 @@ typefmt(Fmt *fp, Type *t)
        }
 
        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]);
        }
@@ -1086,7 +1086,7 @@ exprfmt(Fmt *f, Node *n, int prec)
                        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))
index 8141b968693244e902ce8426c79d0352144f3751..fcbea2cd90c70247bc0ddd695c2a48f6b2673190 100644 (file)
@@ -775,6 +775,7 @@ EXTERN      Idir*   idirs;
 
 EXTERN Type*   types[NTYPE];
 EXTERN Type*   idealstring;
+EXTERN Type*   idealbool;
 EXTERN Type*   bytetype;
 EXTERN Type*   runetype;
 EXTERN Type*   errortype;
index 56f34fde7f7a741c74273972ed600222c00517da..e880b2f34ceb035c1e29dfdd52cd61cc9b0d725b 100644 (file)
@@ -1824,16 +1824,17 @@ lexinit(void)
        // 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;
index 74041fdcedc45252ea166cfc23d849510f7fda53..5621ed9d343fa62040dc4dc1babf805ef980dee2 100644 (file)
@@ -768,7 +768,7 @@ nodbool(int b)
        c = nodintconst(0);
        c->val.ctype = CTBOOL;
        c->val.u.bval = b;
-       c->type = types[TBOOL];
+       c->type = idealbool;
        return c;
 }
 
@@ -929,7 +929,7 @@ isideal(Type *t)
 {
        if(t == T)
                return 0;
-       if(t == idealstring)
+       if(t == idealstring || t == idealbool)
                return 1;
        switch(t->etype) {
        case TNIL:
index 6b0099b8dbe0cb585f316130ddece136bba1f946..0a8a0f09e60deb9c2a1b79e6b32f774d5b76406e 100644 (file)
@@ -20,6 +20,7 @@ func main() {
        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
index 9b8e10ba22d0040dd55d963306c39107f297f74a..d0330ab23892ea40073b7db1e2d8416c36bb49d3 100644 (file)
@@ -31,6 +31,7 @@ func asString(String) {}
 
 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.
@@ -46,7 +47,7 @@ func isString(x interface{}) { _ = x.(String) }
 func main() {
        var (
                a     Array
-               b     Bool   = Bool(true)
+               b     Bool   = true
                c     Chan   = make(Chan)
                f     Float  = 1
                i     Int    = 1
@@ -66,6 +67,7 @@ func main() {
        isBool(b)
        asBool(!b)
        isBool(!b)
+       asBool(true)
        asBool(*&b)
        isBool(*&b)
        asBool(Bool(true))
index 8be7292ca9a6bd4a86f2923b6ffcb261d58b01bb..ca9da0fa31a1cb4b41563b68fcd97e21b3b75f1c 100644 (file)
@@ -26,7 +26,7 @@ type String string
 
 func main() {
        var (
-               b    Bool = Bool(true)
+               b    Bool = true
                i, j int
                c    = make(chan int)
                m    = make(Map)
@@ -34,7 +34,7 @@ func main() {
 
        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"