Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/goPublic

Commit3b7e6e8

Browse files
committed
[release-branch.go1.1] cmd/gc: compute initialization order for top-level blank vars too.
««« CL 8601044 / 3a74e15c5d56cmd/gc: compute initialization order for top-level blank vars too.Fixes#5244.R=golang-dev, rsc, iant, r, daniel.morsingCC=golang-devhttps://golang.org/cl/8601044»»»R=iant, rscCC=golang-devhttps://golang.org/cl/10250043
1 parent13af44f commit3b7e6e8

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

‎src/cmd/gc/sinit.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ init1(Node *n, NodeList **out)
5353
if(isblank(n)&&n->curfn==N&&n->defn!=N&&n->defn->initorder==InitNotStarted) {
5454
// blank names initialization is part of init() but not
5555
// when they are inside a function.
56-
n->defn->initorder=InitDone;
57-
if(debug['%'])dump("nonstatic",n->defn);
58-
*out=list(*out,n->defn);
56+
break;
5957
}
6058
return;
6159
}
@@ -130,7 +128,7 @@ init1(Node *n, NodeList **out)
130128
init2(n->defn->right,out);
131129
if(debug['j'])
132130
print("%S\n",n->sym);
133-
if(!staticinit(n,out)) {
131+
if(isblank(n)||!staticinit(n,out)) {
134132
if(debug['%'])dump("nonstatic",n->defn);
135133
*out=list(*out,n->defn);
136134
}

‎test/fixedbugs/issue5244.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// run
2+
3+
// Copyright 2013 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 5244: the init order computation uses the wrong
8+
// order for top-level blank identifier assignments.
9+
// The example used to panic because it tries calling a
10+
// nil function instead of assigning to f before.
11+
12+
package main
13+
14+
varf=func()int {return1 }
15+
var_=f()+g()
16+
varg=func()int {return2 }
17+
18+
funcmain() {}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp