mirror of
https://github.com/golang/go
synced 2024-11-21 21:54:40 -07:00
gc: implicit type bug fix in export data
TBR=lvd CC=golang-dev https://golang.org/cl/5644064
This commit is contained in:
parent
29df93735c
commit
5c52404aca
@ -1058,7 +1058,7 @@ exprfmt(Fmt *f, Node *n, int prec)
|
||||
NodeList *l;
|
||||
Type *t;
|
||||
|
||||
while(n && n->implicit)
|
||||
while(n && n->implicit && (n->op == OIND || n->op == OADDR))
|
||||
n = n->left;
|
||||
|
||||
if(n == N)
|
||||
@ -1160,13 +1160,13 @@ exprfmt(Fmt *f, Node *n, int prec)
|
||||
return fmtprint(f, "%N{ %,H }", n->right, n->list);
|
||||
|
||||
case OPTRLIT:
|
||||
if (fmtmode == FExp && n->left->right->implicit == Implicit)
|
||||
if(fmtmode == FExp && n->left->implicit)
|
||||
return fmtprint(f, "%N", n->left);
|
||||
return fmtprint(f, "&%N", n->left);
|
||||
|
||||
case OSTRUCTLIT:
|
||||
if (fmtmode == FExp) { // requires special handling of field names
|
||||
if(n->right->implicit == Implicit)
|
||||
if(fmtmode == FExp) { // requires special handling of field names
|
||||
if(n->implicit)
|
||||
fmtstrcpy(f, "{");
|
||||
else
|
||||
fmtprint(f, "%T{", n->type);
|
||||
@ -1194,6 +1194,8 @@ exprfmt(Fmt *f, Node *n, int prec)
|
||||
case OMAPLIT:
|
||||
if(fmtmode == FErr)
|
||||
return fmtprint(f, "%T literal", n->type);
|
||||
if(fmtmode == FExp && n->implicit)
|
||||
return fmtprint(f, "{ %,H }", n->list);
|
||||
return fmtprint(f, "%T{ %,H }", n->type, n->list);
|
||||
|
||||
case OKEY:
|
||||
|
@ -215,13 +215,6 @@ enum
|
||||
EscNever,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Explicit,
|
||||
Implicit, // don't print in output
|
||||
ImplPtr, // OIND added by &T{ ... } literal
|
||||
};
|
||||
|
||||
struct Node
|
||||
{
|
||||
// Tree structure.
|
||||
@ -257,7 +250,7 @@ struct Node
|
||||
uchar used;
|
||||
uchar isddd;
|
||||
uchar readonly;
|
||||
uchar implicit; // Explicit, Implicit, ImplPtr.
|
||||
uchar implicit;
|
||||
uchar addrtaken; // address taken, even if not moved to heap
|
||||
uchar dupok; // duplicate definitions ok (for func)
|
||||
|
||||
|
@ -808,7 +808,7 @@ uexpr:
|
||||
// Special case for &T{...}: turn into (*T){...}.
|
||||
$$ = $2;
|
||||
$$->right = nod(OIND, $$->right, N);
|
||||
$$->right->implicit = ImplPtr;
|
||||
$$->right->implicit = 1;
|
||||
} else {
|
||||
$$ = nod(OADDR, $2, N);
|
||||
}
|
||||
|
@ -2008,7 +2008,8 @@ pushtype(Node *n, Type *t)
|
||||
|
||||
if(n->right == N) {
|
||||
n->right = typenod(t);
|
||||
n->right->implicit = 1;
|
||||
n->implicit = 1; // don't print
|
||||
n->right->implicit = 1; // * is okay
|
||||
}
|
||||
else if(debug['s']) {
|
||||
typecheck(&n->right, Etype);
|
||||
@ -2048,8 +2049,8 @@ typecheckcomplit(Node **np)
|
||||
|
||||
if(isptr[t->etype]) {
|
||||
// For better or worse, we don't allow pointers as the composite literal type,
|
||||
// except when using the &T syntax, which sets implicit to ImplPtr.
|
||||
if(n->right->implicit == Explicit) {
|
||||
// except when using the &T syntax, which sets implicit on the OIND.
|
||||
if(!n->right->implicit) {
|
||||
yyerror("invalid pointer type %T for composite literal (use &%T instead)", t, t->type);
|
||||
goto error;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,23 @@
|
||||
/* A Bison parser, made by GNU Bison 2.3. */
|
||||
|
||||
/* A Bison parser, made by GNU Bison 2.4.1. */
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA. */
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
@ -29,10 +28,11 @@
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
# define YYTOKENTYPE
|
||||
@ -146,22 +146,28 @@
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
#line 28 "go.y"
|
||||
{
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
#line 28 "go.y"
|
||||
|
||||
Node* node;
|
||||
NodeList* list;
|
||||
Type* type;
|
||||
Sym* sym;
|
||||
struct Val val;
|
||||
int i;
|
||||
}
|
||||
/* Line 1529 of yacc.c. */
|
||||
#line 160 "y.tab.h"
|
||||
YYSTYPE;
|
||||
|
||||
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
#line 165 "y.tab.h"
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
||||
|
@ -36,6 +36,8 @@ func F6(S int) *U {
|
||||
return &U{{S,S}}
|
||||
}
|
||||
|
||||
// Bug in the fix.
|
||||
|
||||
type PB struct { x int }
|
||||
|
||||
|
||||
func (t *PB) Reset() { *t = PB{} }
|
||||
|
13
test/fixedbugs/bug392.dir/three.go
Normal file
13
test/fixedbugs/bug392.dir/three.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Use the functions in one.go so that the inlined
|
||||
// forms get type-checked.
|
||||
|
||||
package three
|
||||
|
||||
import "./two"
|
||||
|
||||
var x = two.F()
|
||||
var v = two.V
|
@ -19,3 +19,7 @@ func use() {
|
||||
t.M()
|
||||
t.MM()
|
||||
}
|
||||
|
||||
var V = []one.PB{{}, {}}
|
||||
|
||||
func F() *one.PB
|
||||
|
@ -1,4 +1,4 @@
|
||||
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go
|
||||
// $G $D/$F.dir/one.go && $G $D/$F.dir/two.go && $G $D/$F.dir/three.go
|
||||
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
|
Loading…
Reference in New Issue
Block a user