Commit 866b2723 authored by Russ Cox's avatar Russ Cox

bug186 - f(iota)

R=ken
OCL=33051
CL=33051
parent 68e25051
...@@ -470,6 +470,7 @@ enum ...@@ -470,6 +470,7 @@ enum
Etype = 1<<3, Etype = 1<<3,
Ecall = 1<<4, // call-only expressions are ok Ecall = 1<<4, // call-only expressions are ok
Efnstruct = 1<<5, // multivalue function returns are ok Efnstruct = 1<<5, // multivalue function returns are ok
Eiota = 1<<6, // iota is ok
}; };
#define BITS 5 #define BITS 5
......
...@@ -85,6 +85,8 @@ reswitch: ...@@ -85,6 +85,8 @@ reswitch:
*/ */
case OLITERAL: case OLITERAL:
ok |= Erv; ok |= Erv;
if(n->iota && !(top & Eiota))
yyerror("use of iota outside of constant initializer");
goto ret; goto ret;
case ONONAME: case ONONAME:
...@@ -261,8 +263,8 @@ reswitch: ...@@ -261,8 +263,8 @@ reswitch:
case OSUB: case OSUB:
case OXOR: case OXOR:
ok |= Erv; ok |= Erv;
l = typecheck(&n->left, Erv); l = typecheck(&n->left, Erv | (top & Eiota));
r = typecheck(&n->right, Erv); r = typecheck(&n->right, Erv | (top & Eiota));
if(l->type == T || r->type == T) if(l->type == T || r->type == T)
goto error; goto error;
op = n->op; op = n->op;
...@@ -339,7 +341,7 @@ reswitch: ...@@ -339,7 +341,7 @@ reswitch:
case ONOT: case ONOT:
case OPLUS: case OPLUS:
ok |= Erv; ok |= Erv;
l = typecheck(&n->left, Erv); l = typecheck(&n->left, Erv | (top & Eiota));
if((t = l->type) == T) if((t = l->type) == T)
goto error; goto error;
if(!okfor[n->op][t->etype]) { if(!okfor[n->op][t->etype]) {
...@@ -995,6 +997,8 @@ error: ...@@ -995,6 +997,8 @@ error:
out: out:
lineno = lno; lineno = lno;
n->typecheck = 1; n->typecheck = 1;
if(n->iota)
n->typecheck = 0;
*np = n; *np = n;
return n; return n;
} }
......
...@@ -160,7 +160,7 @@ walkdef(Node *n) ...@@ -160,7 +160,7 @@ walkdef(Node *n)
dump("walkdef nil defn", n); dump("walkdef nil defn", n);
yyerror("xxx"); yyerror("xxx");
} }
typecheck(&e, Erv); typecheck(&e, Erv | Eiota);
if(e->op != OLITERAL) { if(e->op != OLITERAL) {
yyerror("const initializer must be constant"); yyerror("const initializer must be constant");
goto ret; goto ret;
......
// 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
const X = iota
func f(x int) { }
func main() {
f(X);
f(iota); // ERROR "iota.*outside.*initializer"
f(X);
f(iota); // ERROR "iota.*outside.*initializer"
}
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