Skip to content

Generate SyntaxError of global declaration #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Modify symtable test
  • Loading branch information
HyeockJinKim committed Sep 11, 2019
commit 93a13f1437a55909ba2c1a7da47c907f87eebdfd
260 changes: 5 additions & 255 deletions symtable/symtable_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ var symtableTestData = []struct {
Children: Children{},
},
},
}, nil, ""},
}, nil,""},
{"def fn(a):\n global b\n global b\n return b", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Expand Down Expand Up @@ -568,112 +568,8 @@ var symtableTestData = []struct {
},
},
}, nil, ""},
{"def inner():\n print(x)\n global x\n", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Lineno: 0,
Unoptimized: optTopLevel,
Nested: false,
Free: false,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"inner": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
"x": Symbol{
Flags: DefGlobal,
Scope: ScopeGlobalExplicit,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "inner",
Lineno: 1,
Unoptimized: 0,
Nested: false,
Free: false,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"print": Symbol{
Flags: DefUse,
Scope: ScopeGlobalImplicit,
},
"x": Symbol{
Flags: DefGlobal | DefUse,
Scope: ScopeGlobalExplicit,
},
},
Children: Children{},
},
},
}, nil, ""},
{"def fn(a):\n b = 6\n global b\n b = a", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Lineno: 0,
Unoptimized: optTopLevel,
Nested: false,
Free: false,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"b": Symbol{
Flags: DefGlobal,
Scope: ScopeGlobalExplicit,
},
"fn": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "fn",
Lineno: 1,
Unoptimized: 0,
Nested: false,
Free: false,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{"a"},
Symbols: Symbols{
"a": Symbol{
Flags: DefParam | DefUse,
Scope: ScopeLocal,
},
"b": Symbol{
Flags: DefGlobal | DefLocal,
Scope: ScopeGlobalExplicit,
},
},
Children: Children{},
},
},
}, nil, ""},
{"def inner():\n print(x)\n global x\n", "exec", nil, py.SyntaxError, "name 'x' is used prior to global declaration"},
{"def fn(a):\n b = 6\n global b\n b = a", "exec", nil, py.SyntaxError, "name 'b' is assigned to before global declaration"},
{"def fn(a=b,c=1):\n return a+b", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Expand Down Expand Up @@ -817,154 +713,8 @@ var symtableTestData = []struct {
}, nil, ""},
{"def fn(a):\n nonlocal b\n ", "exec", nil, py.SyntaxError, "no binding for nonlocal 'b' found"},
{"def outer():\n def inner():\n nonlocal x\n x = 2", "exec", nil, py.SyntaxError, "no binding for nonlocal 'x' found"},
{"def outer():\n x = 1\n def inner():\n print(x)\n nonlocal x\n", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Lineno: 0,
Unoptimized: optTopLevel,
Nested: false,
Free: false,
ChildFree: true,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"outer": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "outer",
Lineno: 1,
Unoptimized: 0,
Nested: false,
Free: false,
ChildFree: true,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"inner": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
"x": Symbol{
Flags: DefLocal,
Scope: ScopeCell,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "inner",
Lineno: 3,
Unoptimized: 0,
Nested: true,
Free: true,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"print": Symbol{
Flags: DefUse,
Scope: ScopeGlobalImplicit,
},
"x": Symbol{
Flags: DefNonlocal | DefUse,
Scope: ScopeFree,
},
},
Children: Children{},
},
},
},
},
}, nil, ""},
{"def outer():\n x = 1\n def inner():\n x = 2\n nonlocal x", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Lineno: 0,
Unoptimized: optTopLevel,
Nested: false,
Free: false,
ChildFree: true,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"outer": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "outer",
Lineno: 1,
Unoptimized: 0,
Nested: false,
Free: false,
ChildFree: true,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"inner": Symbol{
Flags: DefLocal,
Scope: ScopeLocal,
},
"x": Symbol{
Flags: DefLocal,
Scope: ScopeCell,
},
},
Children: Children{
&SymTable{
Type: FunctionBlock,
Name: "inner",
Lineno: 3,
Unoptimized: 0,
Nested: true,
Free: true,
ChildFree: false,
Generator: false,
Varargs: false,
Varkeywords: false,
ReturnsValue: false,
NeedsClassClosure: false,
Varnames: []string{},
Symbols: Symbols{
"x": Symbol{
Flags: DefLocal | DefNonlocal,
Scope: ScopeFree,
},
},
Children: Children{},
},
},
},
},
}, nil, ""},
{"def outer():\n x = 1\n def inner():\n print(x)\n nonlocal x\n", "exec", nil, py.SyntaxError, "name 'x' is used prior to nonlocal declaration"},
{"def outer():\n x = 1\n def inner():\n x = 2\n nonlocal x", "exec", nil, py.SyntaxError, "name 'x' is assigned to before nonlocal declaration"},
{"def outer():\n x = 1\n def inner(x):\n nonlocal x", "exec", nil, py.SyntaxError, "name 'x' is parameter and nonlocal"},
{"def outer():\n x = 1\n def inner(x):\n global x", "exec", nil, py.SyntaxError, "name 'x' is parameter and global"},
{"def outer():\n def inner():\n global x\n nonlocal x\n ", "exec", nil, py.SyntaxError, "name 'x' is nonlocal and global"},
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy