void
convlit1(Node **np, Type *t, int explicit)
{
- int et, ct;
+ int ct, et;
Node *n, *nn;
n = *np;
- if(n == N || t == T || n->type == T)
+ if(n == N || t == T || n->type == T || isideal(t) || eqtype(t, n->type))
return;
- et = t->etype;
- if(et == TIDEAL || et == TNIL)
- return;
- if(eqtype(t, n->type))
- return;
- if(!explicit && n->type->etype != TIDEAL && n->type != idealstring && n->type->etype != TNIL)
+ if(!explicit && !isideal(n->type))
return;
//dump("convlit1", n);
if(ct < 0)
goto bad;
+ et = t->etype;
if(et == TINTER) {
if(ct == CTNIL && n->type == types[TNIL]) {
n->type = t;
return;
}
- // if already has non-ideal type, cannot change implicitly
- if(!explicit) {
- switch(n->type->etype) {
- case TIDEAL:
- case TNIL:
- break;
- case TSTRING:
- if(n->type == idealstring)
- break;
- // fall through
- default:
- goto bad;
- }
- }
-
switch(ct) {
default:
goto bad;
return;
bad:
- if(n->type->etype == TIDEAL) {
+ if(isideal(n->type)) {
defaultlit(&n, T);
*np = n;
}
Node *n, *nn;
n = *np;
- if(n == N)
- return;
- if(n->type == T || (n->type->etype != TIDEAL && n->type->etype != TNIL))
+ if(n == N || !isideal(n->type))
return;
switch(n->op) {
return;
}
- lno = lineno;
- lineno = n->lineno;
+ lno = setlineno(n);
switch(n->val.ctype) {
default:
if(t != T) {
n->type = T;
break;
}
+ if(n->val.ctype == CTSTR) {
+ n->type = types[TSTRING];
+ break;
+ }
yyerror("defaultlit: unknown literal: %#N", n);
break;
case CTINT:
else
ot = duintptr(s, ot, 0);
}
- ggloblsym(s, ot, 1);
+ ggloblsym(s, ot, 0);
return s;
}
Sym *s, *s1, *s2;
Sig *a, *m;
Type *t1;
+ Sym *tsym;
+
+ if(t->etype == TNIL || t->etype == TIDEAL || t == idealstring)
+ fatal("dtypesym ideal %T", t);
s = typesym(t);
if(s->flags & SymSiggen)
t1 = T;
if(isptr[t->etype])
t1 = t->type;
+ tsym = S;
+ if(t1)
+ tsym = t1->sym;
+ else
+ tsym = t->sym;
if(strcmp(package, "runtime") == 0) {
if(t == types[t->etype])
break;
}
- ggloblsym(s, ot, 1);
+ ggloblsym(s, ot, tsym == nil);
return s;
}
return 0;
}
+int
+isideal(Type *t)
+{
+ if(t == T)
+ return 0;
+ if(t == idealstring)
+ return 1;
+ return t->etype == TNIL || t->etype == TIDEAL;
+}
+
/*
* given receiver of type t (t == r or t == *r)
* return type to hang methods off (r).